[Tutor] using dynamic import statements

Alan Gauld alan.gauld at btinternet.com
Mon Jul 9 13:12:04 CEST 2012


On 09/07/12 10:19, Kwpolska wrote:
> Why does this bloody ML want me to respond to the last person instead
> of tutor at python.org?

Because that's how it, along with many other mailing lists, works.
If it helps, think of it as you receiving a mail from the sender and CCd 
to the list. Therefore hitting reply sends to the person who sent the 
mail and ReplyAll goes to everyone. Seems logical to me! :-)
It allows me to choose to reply to the OP only or to the group, I use 
both depending on the nature of my reply. (About 80% of my replies go to 
the everyone.) But some prefer it differently... :-)

>> Why not the more usual:
>>
>> import sys, os, imp, stat,    \
>>         re, webbrowser, Image, \
>>         StringIO, shutil, datetime
>
> Why not the more standard:
> import sys
> import os
> and so on?  http://www.python.org/dev/peps/pep-0008/#imports

Indeed but the OP seemed to want to remove duplicate coding so I assumed 
that he included using multiple imports.

Personally I'd probably code the above as:

import sys, os, shutil, stat, datetime
import re, StringIO
import webbrowser,
import Image,
import imp

Which groups things into roughly related categories - system,
strings, other...

OTOH I ignore large chunks of Pep 8 because I find its style harder to 
read than the one I'm used to. But then, I'm not contributing to the 
standard library etc... Style is largely a matter of taste.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list