EuroPython 2021: Free tickets for Python Core Developers
In 2019, we have set up the Guido van Rossum Core Developer Grant, to make it easy for Python Core Developers to attend EuroPython, but also to give something back to the core team and add a perk to make core development more attractive. If you are a core developer, please check our grant page for details on how to apply: https://www.europython-society.org/core-grant PS: If you are a core developer and want to organize a core sprint, workshop, language summit or similar event at EuroPython 2021, please get in touch with our program workgroup soon, so that we can help arrange things: [email protected] PPS: If you want to become a core developer, please have a look at the Python Dev Guide: https://devguide.python.org/coredev/ Quick Summary - EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. More infos are available on our website at https://ep2021.europython.eu/ Help spread the word Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-schedule-published/ Tweet: https://twitter.com/europython/status/1405538503048327169 Enjoy, -- EuroPython 2021 Team https://ep2021.europython.eu/ https://www.europython-society.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: How to iterate through maildir messages in python 3?
Greg Ewing wrote: > On 25/06/21 7:06 am, Chris Green wrote: > > In python 2 one can do:- > > > > for msg in maildir: > >print msg # or whatever you want to do with the message > > > > > > However in python 3 this produces "TypeError: string argument > > expected, got 'bytes'". > > > > How should one iterate over a maildir in python3? > > You're already iterating over it just fine. Your problem is > actually how to *print* a mail message. > > The answer to this will depend on what your purpose is. If > you just want a rough-and-ready idea of what the message > contains, you could do this: > > print(repr(msg)) > > However, that won't work very well if the message doesn't > consist of mostly text in an ASCII-compatible encoding. > > If you want something better, Python comes with some standard > library code for dealing with mail messages. Check out the > 'email' module. > The error comes from the line "for msg in maildir:", not the print. Here's the full program where I'm encountering the error (yes, I should have posted this first time around) :- #!/usr/bin/python3 import mailbox import sys import email #open the existing maildir and the target mbox file maildir = mailbox.Maildir(sys.argv [-2], email.message_from_file) mbox = mailbox.mbox(sys.argv[-1]) #lock the mbox mbox.lock() #iterate over messages in the maildir and add to the mbox for msg in maildir: mbox.add(msg) #close and unlock mbox.close() maildir.close() (... and it's not my coding style, just copied) Here's the error trace:- chris$ ./md.py houseSitting fred Traceback (most recent call last): File "/home/chris/tmp/./md.py", line 18, in for msg in maildir: File "/usr/lib/python3.9/mailbox.py", line 110, in itervalues value = self[key] File "/usr/lib/python3.9/mailbox.py", line 77, in __getitem__ return self._factory(file) File "/usr/lib/python3.9/email/__init__.py", line 54, in message_from_file return Parser(*args, **kws).parse(fp) File "/usr/lib/python3.9/email/parser.py", line 56, in parse feedparser.feed(data) File "/usr/lib/python3.9/email/feedparser.py", line 175, in feed self._input.push(data) File "/usr/lib/python3.9/email/feedparser.py", line 103, in push self._partial.write(data) TypeError: string argument expected, got 'bytes' chris$ Line 18 is the "for msg in maildir:". Presumably the program worked as posted under python 2, all I have done is to change the shebang line to use python 3 (I no longer have python 2 on my system, otherwise I'd have used it as this is only a quick and dirty conversion script to be used once). -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
Re: How to iterate through maildir messages in python 3?
Gilmeh Serda wrote: > On Fri, 25 Jun 2021 09:19:49 +0100, Chris Green wrote: > > > TypeError: string argument expected, got 'bytes' > > couple things comes to mind: > > 1. find py2 as archive, put it somewhere and run it from that > Hmm! :-) > 2. convert the bytes to str (find and replace) > How? It's failing at "for msg in maildir:", you can't change it to "for str(msg) in maildir" (well you can but it gives a syntax error). > 3. run the py2>py3 conversion script > That does nothing, says "No files need to be modified" -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
Re: How to iterate through maildir messages in python 3?
On Sat, Jun 26, 2021 at 12:28 AM Chris Green wrote: > > Greg Ewing wrote: > > On 25/06/21 7:06 am, Chris Green wrote: > > > In python 2 one can do:- > > > > > > for msg in maildir: > > >print msg # or whatever you want to do with the message > > > > > > > > > However in python 3 this produces "TypeError: string argument > > > expected, got 'bytes'". > > > > > > How should one iterate over a maildir in python3? > > > > You're already iterating over it just fine. Your problem is > > actually how to *print* a mail message. > > > > The answer to this will depend on what your purpose is. If > > you just want a rough-and-ready idea of what the message > > contains, you could do this: > > > > print(repr(msg)) > > > > However, that won't work very well if the message doesn't > > consist of mostly text in an ASCII-compatible encoding. > > > > If you want something better, Python comes with some standard > > library code for dealing with mail messages. Check out the > > 'email' module. > > > The error comes from the line "for msg in maildir:", not the print. > > Here's the full program where I'm encountering the error (yes, I > should have posted this first time around) :- > > #!/usr/bin/python3 > > import mailbox > import sys > import email > > > #open the existing maildir and the target mbox file > maildir = mailbox.Maildir(sys.argv [-2], email.message_from_file) > mbox = mailbox.mbox(sys.argv[-1]) > > #iterate over messages in the maildir and add to the mbox > for msg in maildir: > mbox.add(msg) > Maildir says that the factory has to take a binary file object. It looks like email.message_from_file is expecting a text file object, but there's a very similar function message_from_binary_file that might be what you want. Haven't tested it, but worth a try. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
