Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Chris Angelico
On Wed, May 26, 2021 at 4:21 PM Grant Edwards wrote: > > On 2021-05-25, Dennis Lee Bieber wrote: > > >>Oh ok, it seemed to be fine. Would it be the right way to do it with > >>sys.exit()? Having to import another library just to end a program > >>might not be ideal. > > > > I've never had

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Grant Edwards
On 2021-05-25, Dennis Lee Bieber wrote: >>Oh ok, it seemed to be fine. Would it be the right way to do it with >>sys.exit()? Having to import another library just to end a program >>might not be ideal. > > I've never had to use sys. for exit... I would have sworn you used to have to im

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Grant Edwards
On 2021-05-25, Dennis Lee Bieber wrote: > On Tue, 25 May 2021 19:21:39 +0200, hw declaimed the > following: > > >> >>Oh ok, it seemed to be fine. Would it be the right way to do it with >>sys.exit()? Having to import another library just to end a program >>might not be ideal. > > I've n

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Cameron Simpson
On 25May2021 19:21, hw wrote: >On 5/25/21 11:38 AM, Cameron Simpson wrote: >>On 25May2021 10:23, hw wrote: >>>if status != 'OK': >>>print('Login failed') >>>exit >> >>Your "exit" won't do what you want. I expect this code to raise a >>NameError exception here (you've not defined "exit").

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Cameron Simpson
On 25May2021 15:53, Dennis Lee Bieber wrote: >On Tue, 25 May 2021 19:21:39 +0200, hw declaimed the >following: >>Oh ok, it seemed to be fine. Would it be the right way to do it with >>sys.exit()? Having to import another library just to end a program >>might not be ideal. > > I've never h

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 2021-05-24, Alan Gauld via Python-list wrote: Although wouldn't it be "expected boolean expression" rather than conditional expression? Python doesn't care how the argument to 'if' is arrived at so long as it's a boolean. This isn't really true either. Almost every object in Python has an

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 26/05/21 3:33 am, Dennis Lee Bieber wrote: the OBJECTS have a type and can not change type. Well... built-in types can't, but... >>> class A: ... pass ... >>> class B: ... pass ... >>> a = A() >>> type(a) >>> a.__class__ = B >>> type(a) -- Greg -- https://mail.python.org/mailman/listi

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Greg Ewing
On 26/05/21 5:21 am, hw wrote: On 5/25/21 11:38 AM, Cameron Simpson wrote: You'll need to import "sys". aving to import another library just to end a program might not be ideal. The sys module is built-in, so the import isn't really loading anything, it's just giving you access to a namespa

Re: learning python ...

2021-05-25 Thread Manfred Lotz
On Mon, 24 May 2021 08:14:39 +1200 Ron.Lauzon@f192.n1.z21.fsxnet (Ron Lauzon) wrote: > -=> hw wrote to All <=- > > hw> Traceback (most recent call last): > hw>File "[...]/hworld.py", line 18, in > hw> print(isinstance(int, float)) > hw> TypeError: isinstance() arg 2 must be a type

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Terry Reedy
On 5/25/2021 1:25 PM, MRAB wrote: On 2021-05-25 16:41, Dennis Lee Bieber wrote: In Python 3, strings are UNICODE, using 1, 2, or 4 bytes PER CHARACTER This is CPython 3.3+ specific. Before than, it depended on the OS. I believe MicroPython uses utf-8 for strings. (I don't recall if

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Chris Angelico
On Wed, May 26, 2021 at 8:27 AM Grant Edwards wrote: > > On 2021-05-25, MRAB wrote: > > On 2021-05-25 16:41, Dennis Lee Bieber wrote: > > >> In Python 3, strings are UNICODE, using 1, 2, or 4 bytes PER > >> CHARACTER (I don't recall if there is a 3-byte version). If your > >> input bytes are all

Re: learning python ...

2021-05-25 Thread Michael F. Stemper
On 24/05/2021 18.30, Alan Gauld wrote: On 24/05/2021 16:54, Michael F. Stemper wrote: In my early days of writing python, I created lists named "list", dictionaries named "dict", and strings named "str". I mostly know better now, but sometimes still need to restrain my fingers. I think most n

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Grant Edwards
On 2021-05-25, MRAB wrote: > On 2021-05-25 16:41, Dennis Lee Bieber wrote: >> In Python 3, strings are UNICODE, using 1, 2, or 4 bytes PER >> CHARACTER (I don't recall if there is a 3-byte version). If your >> input bytes are all 7-bit ASCII, then they map directly to a 1-byte >> per character st

Re: learning python ...

2021-05-25 Thread Grant Edwards
On 2021-05-25, Michael F. Stemper wrote: > On 24/05/2021 23.08, hw wrote: >> On 5/25/21 12:37 AM, Greg Ewing wrote: >> >> Are all names references?  When I pass a name as a parameter to a >> function, does the object the name is referring to, when altered by the >> function, still appear altere

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread MRAB
On 2021-05-25 16:41, Dennis Lee Bieber wrote: On Tue, 25 May 2021 10:23:41 +0200, hw declaimed the following: So I'm forced to convert stuff from bytes to strings (which is weird because bytes are bytes) and to use regular expressions to extract the message-uids from what the functions retu

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread hw
On 5/25/21 11:38 AM, Cameron Simpson wrote: On 25May2021 10:23, hw wrote: I'm about to do stuff with emails on an IMAP server and wrote a program using imaplib which, so far, gets the UIDs of the messages in the inbox: #!/usr/bin/python I'm going to assume you're using Python 3. Python 3.

Re: learning python ...

2021-05-25 Thread Michael F. Stemper
On 24/05/2021 23.08, hw wrote: On 5/25/21 12:37 AM, Greg Ewing wrote: Python does have references to *objects*. All objects live on the heap and are kept alive as long as there is at least one reference to them. If you rebind a name, and it held the last reference to an object, there is no wa

Re: learning python ...

2021-05-25 Thread Grant Edwards
On 2021-05-25, Greg Ewing wrote: > On 25/05/21 5:56 pm, Avi Gross wrote: >> Var = read in something from a file and make some structure like a data.frame >> Var = remove some columns from the above thing pointed to by Var >> Var = make some new calculated columns ditto >> Var = remove some rows ..

Re: learning python ...

2021-05-25 Thread Grant Edwards
On 2021-05-24, Alan Gauld via Python-list wrote: > On 24/05/2021 19:48, Grant Edwards wrote: > >>> Traceback ( File "", line 1 >>> if = 1.234 >>>^ >>> SyntaxError: invalid syntax >> >> I must admit it might be nice if the compiler told you _why_ the >> syntax is invalid (e.g. "expect

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Grant Edwards
On 2021-05-25, hw wrote: > I'm about to do stuff with emails on an IMAP server and wrote a program > using imaplib My recollection of using imaplib a few years ago is that yes, it is unweildy, oddly low-level, and rather un-Pythonic (excuse my presumption in declaring what is and isn't "Pythoni

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 25/05/21 5:56 pm, Avi Gross wrote: Var = read in something from a file and make some structure like a data.frame Var = remove some columns from the above thing pointed to by Var Var = make some new calculated columns ditto Var = remove some rows ... Var = set some kind of grouping on the above

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 25/05/21 2:59 pm, hw wrote: Then what is 'float' in the case of isinstance() as the second parameter, and why can't python figure out what 'float' refers to in this case? You seem to be asking for names to be interpreted differently when they are used as parameters to certain functions.

Re: learning python ...

2021-05-25 Thread Alan Gauld via Python-list
On 25/05/2021 00:41, Jon Ribbens via Python-list wrote: > What would you call the argument to a function that > returns, say, an upper-cased version of its input? Probably 'candidate' or 'original' or 'initial' or somesuch. Or even just 's'. Single character names are OK when there is no signifi

Re: learning python ...

2021-05-25 Thread Michael Torrie
On 5/24/21 9:53 PM, hw wrote: > That seems like an important distinction. I've always been thinking of > variables that get something assigned to them, not as something that is > being assigned to something. Your thinking is not incorrect. Assignment is how you set a variable to something. Fo

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Skip Montanaro
> It's working (with Cyrus), but I have the feeling I'm doing it all wrong > because it seems so unwieldy. I have a program, Polly , which I wrote to generate XKCD 936 passphrases. (I got the idea - and the name - from Chris Angelico. See the README.) It builds

Re: learning python ...

2021-05-25 Thread Richard Damon
On 5/25/21 12:08 AM, hw wrote: > > Are all names references?  When I pass a name as a parameter to a > function, does the object the name is referring to, when altered by > the function, still appear altered after the function has returned?  I > wouldn't expect that ... If you mutate the object th

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Chris Angelico
On Tue, May 25, 2021 at 8:21 PM Cameron Simpson wrote: > When you go: > > text = str(data) > > that is _assuming_ a particular text encoding stored in the data. You > really ought to specify an encoding here. If you've not specified the > CHARSET for things, 'ascii' would be a conservative cho

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Cameron Simpson
On 25May2021 10:23, hw wrote: >I'm about to do stuff with emails on an IMAP server and wrote a program >using imaplib which, so far, gets the UIDs of the messages in the >inbox: > > >#!/usr/bin/python I'm going to assume you're using Python 3. >import imaplib >import re > >imapsession = imapli

Shadowing, was Re: learning python ...

2021-05-25 Thread Peter Otten
On 25/05/2021 05:20, hw wrote: We're talking about many different things. If it's simply "num = ..." followed by "num = ...", then it's not a new variable or anything, it's simply rebinding the same name. But when you do "int = ...", it's shadowing the builtin name. Why?  And how is that "shad

Re: learning python ...

2021-05-25 Thread Chris Angelico
On Tue, May 25, 2021 at 1:00 PM hw wrote: > > On 5/24/21 3:54 PM, Chris Angelico wrote: > > You keep using that word "unfinished". I do not think it means what > > you think it does. > > What do you think I think it means? I think it means that the language is half way through development, doesn'

imaplib: is this really so unwieldy?

2021-05-25 Thread hw
Hi, I'm about to do stuff with emails on an IMAP server and wrote a program using imaplib which, so far, gets the UIDs of the messages in the inbox: #!/usr/bin/python import imaplib import re imapsession = imaplib.IMAP4_SSL('imap.example.com', port = 993) status, data = imapsession.login