If I were to import some module called modx, how would that be different from saying
from modx import *
Wouldn't all the contents be imported from each either way? This is in python just to clarify.
If I were to import some module called modx, how would that be different from saying
from modx import *
Wouldn't all the contents be imported from each either way? This is in python just to clarify.
Common question with many faq's to answer... here is one: http://effbot.org/zone/import-confusion.htm
Essentially to answer your specific question the second form (
from modx import *
) you get only the public items in modxIf you
import somemodule
the contained globals will be available viasomemodule.someglobal
. If youfrom somemodule import *
ALL its globals (or those listed in__all__
if it exists) will be made globals, i.e. you can access them usingsomeglobal
without the module name in front of it.Using
from module import *
is discouraged as it clutters the global scope and if you import stuff from multiple modules you are likely to get conflicts and overwrite existing classes/functions.If
a
definesa.b
anda.c
...vs.
vs.
Note that
from foo import *
is generally frowned upon since: