advice on this little script
Alex Martelli
aleaxit at yahoo.com
Thu Mar 9 10:29:08 EST 2006
John Salerno <johnjsal at NOSPAMgmail.com> wrote:
> Alex Martelli wrote:
>
> > I only use the 'from' statement to import specific modules from a
> > package, never to import specific objects (functions, classes, or
> > whatever) from a module.
>
> I like that. So in my case I'd use 'import time' (which I actually
> already changed last night). I think especially right now, while I'm new
> to Python, it helps me to see 'time.sleep' instead of just 'sleep', so I
> can begin to associate certain functions with their proper modules.
I'm hardly new to Python, yet it keeps helping me too;-).
> Not to mention, like you said, that importing specific pieces like
> functions tends to look a little messy in the code when they aren't
> qualified.
I wouldn't call it messy, but rather potentially "confusing" in a large
module with many imports -- in the middle of the module,
a = b(c)
always gives the strong impression that b and cc are local or global (or
from an intermediate lexical scope), while
a = X.b(Y.c)
contains hints suggesting otherwise (if I had no clue what X and Y were
at this point, I'd _first_ check if they were imported modules, while it
would be my last resort in the former snippet regarding b and c).
Alex
More information about the Python-list
mailing list