On 2023-03-19, Stefan Ram <r...@zedat.fu-berlin.de> wrote: > Peng Yu <pengyu...@gmail.com> writes: >>But when I try the following code, get_body() is not found. How to get >>get_body() to work? > > Did you know that this post of mine here was posted to > Usenet with a Python script I wrote? > > That Python script has a function to show the body of > a post before posting. The post is contained in a file, > so it reads the post from that file. > > I copy it here, maybe it can help some people to see > how I do this. > > # Python 3.5 > > import email > > ... > > def showbody( file ): # lightly edited for posting on 2023-03-19 > output = '' > msg = email.message_from_binary_file\ > ( file, policy=email.policy.default )
I wouldn't generally be pedantic about code style, but that's giving me painful convulsions. Backslashes for line continuations are generally considered a bad idea (as they mean that any whitespace after the backslash, which is often invisible, becomes significant). And not indenting the continuation line(s) is pretty shocking. Writing it as below is objectively better: msg = email.message_from_binary_file( file, policy=email.policy.default ) (Also, I too find it annoying to have to avoid, but calling a local variable 'file' is somewhat suspect since it shadows the builtin.) -- https://mail.python.org/mailman/listinfo/python-list