Alex Martelli wrote: > John Salerno <[EMAIL PROTECTED]> 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 use both fairly interchangeably. When I just need one or two things from the module, or if I am going to use something a lot, I use from xx import yy. > > > 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). If you use from xx import yy, searching for yy will show you its provenance as well. From xx import * is evil because it does hide the provenance of names. It can also give unexpected results - if xx contains from zz import *, then all of the names from zz will also be imported into the module importing xx! Kent -- http://mail.python.org/mailman/listinfo/python-list