Simple question regarding module initialization
Troy Melhase
troy.melhase at gmail.com
Tue Jun 20 21:53:34 EDT 2006
$ ipython
in [1]: __import__?
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in function __import__>
Namespace: Python builtin
Docstring:
__import__(name, globals, locals, fromlist) -> module
Import a module. The globals are only used to determine the context;
they are not modified. The locals are currently unused. The fromlist
should be a list of names to emulate ``from name import ...'', or an
empty list to emulate ``import name''.
When importing a module from a package, note that __import__('A.B', ...)
returns package A when fromlist is empty, but its submodule B when
fromlist is not empty.
On 6/20/06, Patrick M. Nielsen <thirsteh at gmail.com> wrote:
> Hi guys.
>
> Yes, this is very much a neophyte question, but I was pondering;
>
> modules = ['stackless',
> 'sys',
> 'slsocket as socket',
> 'random, time',
> 'traceback',
> 'string',
> 'util']
>
> for module in modules:
> print "Loading %s..." % module
> exec 'import %s' % module
>
>
> Although I like the outcome of writing it like this, I don't feel good about
> it. Is this against standard Python conventions or morals? Loading modules
> this way, that is (instead of just importing it all "the right way" and
> making a print statement for each one).
>
>
More information about the Python-list
mailing list