Re: How do I do this in Python 3 (string.join())?

2020-08-28 Thread Chris Green
Cameron Simpson wrote: [snip] > > >The POP3 processing is solely to collect E-Mail that ends up in the > >'catchall' mailbox on my hosting provider. It empties the POP3 > >catchall mailbox, checks for anything that *might* be for me or other > >family members then just deletes the rest. > > Ver

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Cameron Simpson
On 27Aug2020 14:36, Chris Green wrote: >Cameron Simpson wrote: >> I do ok, though most of my message processing happens to messages >> already landed in my "spool" Maildir by getmail. My setup uses getmail >> to get messages with POP into a single Maildir, and then I process the >> message files

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Chris Green
Cameron Simpson wrote: > On 27Aug2020 09:16, Chris Green wrote: > >Cameron Simpson wrote: > >> But note: joining bytes like strings is uncommon, and may indicate > >> that > >> you should be working in strings to start with. Eg you may want to > >> convert popmsg from bytes to str and do a str.

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Cameron Simpson
On 27Aug2020 09:16, Chris Green wrote: >Cameron Simpson wrote: >> But note: joining bytes like strings is uncommon, and may indicate >> that >> you should be working in strings to start with. Eg you may want to >> convert popmsg from bytes to str and do a str.join anyway. It depends on >> exactl

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Chris Green
Cameron Simpson wrote: > On 26Aug2020 15:09, Chris Green wrote: > >2qdxy4rzwzuui...@potatochowder.com wrote: > >> Join bytes objects with a byte object: > >> > >> b"\n".join(popmsg[1]) > > > >Aaahhh! Thank you (and the other reply). > > But note: joining bytes like strings is uncommon, and

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread Cameron Simpson
On 26Aug2020 15:09, Chris Green wrote: >2qdxy4rzwzuui...@potatochowder.com wrote: >> Join bytes objects with a byte object: >> >> b"\n".join(popmsg[1]) > >Aaahhh! Thank you (and the other reply). But note: joining bytes like strings is uncommon, and may indicate that you should be working i

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread Chris Green
2qdxy4rzwzuui...@potatochowder.com wrote: > On 2020-08-26 at 14:22:10 +0100, > Chris Green wrote: > > > I have the following line in Python 2:- > > > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing > the lines of the message > > > > ... so I changed it to:- > > > >

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread MRAB
On 2020-08-26 14:22, Chris Green wrote: I have the following line in Python 2:- msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing the lines of the message ... so I changed it to:- s = "\n" msgstr = s.join(popmsg[1]) # popmsg[1] is a list containin

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread D'Arcy Cain
On 2020-08-26 09:22, Chris Green wrote: > I have the following line in Python 2:- > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list > containing the lines of the message > > ... so I changed it to:- > > s = "\n" > msgstr = s.join(popmsg[1]) # popmsg[1] is a l

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread 2QdxY4RzWzUUiLuE
On 2020-08-26 at 14:22:10 +0100, Chris Green wrote: > I have the following line in Python 2:- > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list > containing the lines of the message > > ... so I changed it to:- > > s = "\n" > msgstr = s.join(popmsg[1]) # po

Re: How do i do this

2005-07-24 Thread Diez B.Roggisch
Amit Regmi neolinuxsolutions.com> writes: > For some commad Linux like (pdbedit) its not possible to supply password > in the command line itself while we add a samba user account into the You might be able to utilize pexpect for this. Go google :) Diez -- http://mail.python.org/mailman/lis

Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Carl Banks
> From my point of view, they're basically identical, and > although I find Carl's approach slightly less explicit > and harder to read (mainly the uncommon __import__ call, > but it's not a big deal), I can't see why either of them > would be considered evil. Of course, when I said evil, I didn't

Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Peter Hansen
Carl Banks wrote: It's a bit more honest to set module attributes using setattr than dict access, I would say. Granted. But I think it's also more honest to change a module's dict by using globals() than by using a setattr call. <0.500 wink> -Peter -- http://mail.python.org/mailman/listinfo/pytho

Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Peter Hansen
Carl Banks wrote: Nick Coghlan wrote: to that module is far more evil than playing with globals() ;) I'd say using globals() is far eviler. I don't understand either of you. ;-) From my point of view, they're basically identical, and although I find Carl's approach slightly less explicit and hard

Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Carl Banks
Nick Coghlan wrote: > Well, aside from the detail that modifying a module's contents via a reference > to that module is far more evil than playing with globals() ;) > > Even if that module is the one you're running in. . . It seems to me that that which makes modifying a module's contents via a r

Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Nick Coghlan
Carl Banks wrote: Modifying globals() not even necessary for this. When I want to dynamically update the global namespace, I do it this way: mod = __import__(__name__) setattr(mod,symbol,value) Works perfectly unless you're worried about someone modifying the built in __import__. Well, aside from

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Carl Banks
Peter Hansen wrote: > In general I would say that mucking with globals() like this is > probably best restricted to constants like in this case, if at all. Modifying globals() not even necessary for this. When I want to dynamically update the global namespace, I do it this way: mod = __import__(

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Jeff Shannon
Peter Hansen wrote: The main way I use this is in some sort of a "const" module, which provides access to a large set of constant information. In other words, in contrast to what you had in mind when you wrote the above, I'm dealing with neither "variables" nor information that _would_ best be put

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Caleb Hattingh
Jeff I do the same thing in Delphi -> prepend "Self" before all the members in class methods even though its not required. I do it partially for the same reason as you - so I can grok which variables are local and which are global (well, global within the class, anyway). The other reason is

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Peter Hansen
Jeff Shannon wrote: Of course, just because modifications of the dict returned by globals() *do* reliably result in modifications to the global namespace, doesn't mean it's a good idea. ;) "The" global namespace misses the possibility that doing this in "a" global namespace might be a good idea.

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Jeff Shannon
Nick Coghlan wrote: Peter Hansen wrote: Nick, could you please comment on why you say this about globals()? I've never heard of any possibility of "unreliability" in updating globals() and, as far as I know, a large body of code exists which does in fact rely on this -- much of mine included. ;-)

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Bengt Richter
On Tue, 07 Dec 2004 21:12:24 GMT, "It's me" <[EMAIL PROTECTED]> wrote: > >"Caleb Hattingh" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> Hi It's me >> >> > >> > a = 3 >> > y = "a" >> > print eval(y) >> > >> >> To get 'a' to be 4 here, you would say >> >> a = 4 >> > >O

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread caleb . hattingh
Both Peters :) Sure, I must concede that the problem here was my expectation of how things should work. Thanks for the explanations. I still don't really know whether this behaviour of locals() is the result of a design decision, or an implementation artifact of CPython, but at least I have a cl

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Nick Coghlan
Peter Hansen wrote: Nick Coghlan wrote: Generally, altering the contents of the dicts returned by locals() and globals() is unreliable at best. Nick, could you please comment on why you say this about globals()? I've never heard of any possibility of "unreliability" in updating globals() and, as

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Peter Otten
Caleb Hattingh wrote: > I am convinced now that locals() doesn't work as (I) expected. Steven > says there was some or other reason why locals() as used in this context > is not writable - Do you know why this is? I really do not like > guidelines like "may not work", "is unreliable" and so on.

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Peter Otten
Peter Hansen wrote: > Caleb Hattingh wrote: >> I am convinced now that locals() doesn't work as (I) expected. Steven >> says there was some or other reason why locals() as used in this >> context is not writable - Do you know why this is? I really do not >> like guidelines like "may not work",

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Peter Hansen
Caleb Hattingh wrote: I am convinced now that locals() doesn't work as (I) expected. Steven says there was some or other reason why locals() as used in this context is not writable - Do you know why this is? I really do not like guidelines like "may not work", "is unreliable" and so on. P

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Caleb Hattingh
Thx Peter I verified this situation myself with a post from Steven Bethard earlier (trying to use "locals" within a function definition). I am convinced now that locals() doesn't work as (I) expected. Steven says there was some or other reason why locals() as used in this context is not wri

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Peter Otten
Caleb Hattingh wrote: > In what way is it unreliable?  I can't seem to create a situation where > the update through globals and locals doesn't work.   Are you referring Updates to a locals() dictionary may not be reflected by the variables in the local scope, e. g.: >>> def f(): ... locals(

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Caleb Hattingh
Peter, I second that. Nick In what way is it unreliable? I can't seem to create a situation where the update through globals and locals doesn't work. Are you referring perhaps to the possibility of variables being garbage collected and then not being around later when one tries to access t

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Peter Hansen
Nick Coghlan wrote: Generally, altering the contents of the dicts returned by locals() and globals() is unreliable at best. Nick, could you please comment on why you say this about globals()? I've never heard of any possibility of "unreliability" in updating globals() and, as far as I know, a larg

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Nick Coghlan
Caleb Hattingh wrote: '>>> a # The value of a is changed. 8 '>>> The value of a is changed. . . *maybe*. The Python language definition states explicitly that updates to the dictionary returned by locals() may not actually alter the local variables. Generally, altering the contents o

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Nick Coghlan
It's me wrote: Yes, Russell, what you suggested works. I have to chew more on the syntax to see how this is working. because in the book that I have, it says: exec code [ in globaldict [, localdict] ] The [] indicate the last two parts are optional. If you don't supply them, exec just uses the

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Steven Bethard
It's me wrote: For simplicity sake, let's say I need to do something like this (for whatever reason): If I had a situation like this, I'd probably store my 'variables' as keys in a dict, e.g.: >>> bindings = {} >>> for i in range(3): ... name = raw_input('Name: ') ... value = int(raw_i

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread It's me
Thanks for all the replies and yes I realize the associated issue of doing something like this. For simplicity sake, let's say I need to do something like this (for whatever reason): In situations like this, I wouldn't know the name of the variable in Python I need to use ahead of time and so

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread It's me
Yes, Russell, what you suggested works. I have to chew more on the syntax to see how this is working. because in the book that I have, it says: exec code [ in globaldict [, localdict] ] ... -- It's me "Russell Blau" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "It's me"

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Steven Bethard
It's me wrote: How do I do something like this: I know that a = 3 y = "a" print eval(y) would give me a print out of 3 - but how do I do something to the effect of: eval(y) = 4# hopefully the value of a gets changed to 4 Generally, if you find yourself doing this, you may want t

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Craig Ringer
On Wed, 2004-12-08 at 05:12, It's me wrote: > There are many situations where this is useful. For instance, you might be > getting an input which is a string representing the name of a variable and > you wish to evaluate the expression (like a calculator application, for > instance). While I do

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Erik Max Francis
It's me wrote: In REXX, for instance, one can do a: interpret y' = 4' Since y contains a, then the above statement amongs to: a = 4 The direct equivalent in Python would be a = 3 y = 'a' exec '%s = 4' % y The better question would be whether or not this as useful as

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Russell Blau
"It's me" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > In REXX, for instance, one can do a: > > interpret y' = 4' > > Since y contains a, then the above statement amongs to: > > a = 4 > > There are many situations where this is useful. For instance, you might be > getti

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Caleb Hattingh
Sure, ok, I think I am with you now. You get a (e.g.) variable name as a string, and you KNOW how to evaluate it with "eval", but you also want to be able to assign back to (through) the string representation? One way (if I understand you correctly) is with the globals or locals dicts. Try

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread It's me
"Caleb Hattingh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi It's me > > > > > a = 3 > > y = "a" > > print eval(y) > > > > To get 'a' to be 4 here, you would say > > a = 4 > Obviously but that's not what I wish to do. > I am not sure why you would want to do othe

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Caleb Hattingh
Hi It's me a = 3 y = "a" print eval(y) To get 'a' to be 4 here, you would say a = 4 I am not sure why you would want to do otherwise? Perhaps you could sketch out a little more about what you are trying to do? That would help a lot. Are you aiming for something like point