advice on this little script

Alex Martelli aleaxit at yahoo.com
Thu Mar 9 01:42:47 EST 2006


John Salerno <johnjsal at NOSPAMgmail.com> wrote:
   ...
> I think the 'from time import sleep' looks cleaner, because I'm only 
> taking what I need (is an import any more expensive than this from?),
> but I also feel like the 'time.sleep' syntax is much more 
> self-describing and better to read than just 'sleep'.
> 
> So what do you guys think between these two choices?

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. It scales much better: when reading a long
module, I _know_ that any barename X always refers to a local,
nested-scope, or global name, never to something snatched from
who-recalls-what module -- in the latter case I'll never see a barename,
but always somemodule.X, and searching for '... import somemodule' will
immediately tell me where somemodule was coming from (should I need to
be reminded of that information).


Alex



More information about the Python-list mailing list