Question about details of __import__

Gabriel Genellina gagsl-py2 at
Thu Mar 29 20:43:46 CEST 2007

En Thu, 29 Mar 2007 14:42:33 -0300, Mitko Haralanov <mitko at>  

> I have three modules that a comprising the problem:
> ./
> ./
> ./resources/simple/

Surely there is a ./resources/ too?

> The problem that I am seeing is that 'global_info' in the module
> is [None, None, None] on both calls of log.Logger (), even though the
> initial call (from sets it to the passed in values.
> According to the Python documentation, I am using the __import__
> statement correctly to get what I want? It seems like, the guts of the
> import/__import__ code are creating two different namespaces for the
> module.

You may check if this is the case, looking at sys.modules

>  (if you are wondering why I am using __import__ in my class
> constructor, it is because the name of the module that should be
> imported is read out of a configuration file).

Anyway you could import the package and lookup the module inside using  

import resources
name = "simple"
module = getattr(resources, name) = module.Resource()

Gabriel Genellina

More information about the Python-list mailing list