[Tutor] Question on "import foobar" vs "from foobar import *"
spir
denis.spir at free.fr
Sat Jan 9 09:50:08 CET 2010
Lie Ryan dixit:
> only use "from module import *" if the
> module was designed for such use
In most cases, this translates to: the imported module defines __names__, which holds the list of names (of the objects) to be exported. Check it.
Below, a,b,c,f,g,X,Y are defined, but only c,g,Y are exported. This means "from mod import *" will only import these names. Without __names__ defined, it would import all.
### module mod.py ###
__names__ = ['c','g','Y']
a = ...
b = ...
c = ...
def f():
...
def g():
...
class X(object):
...
class Y(object):
...
Denis
________________________________
la vita e estrany
http://spir.wikidot.com/
More information about the Tutor
mailing list