Question about details of __import__
Mitko Haralanov
mitko at qlogic.com
Thu Mar 29 14:56:54 EDT 2007
On Thu, 29 Mar 2007 15:43:46 -0300
"Gabriel Genellina" <gagsl-py2 at yahoo.com.ar> wrote:
> Surely there is a ./resources/__init__.py too?
There sure is:
./resources/__init__.py is:
__all__ = ['simple', 'other']
> You may check if this is the case, looking at sys.modules
I did look at sys.modules but I wasn't sure what to look for. There was
a log module in the list but what else should I look for?
> Anyway you could import the package and lookup the module inside
> using getattr:
>
> import resources
> name = "simple"
> module = getattr(resources, name)
> self.rs = module.Resource()
Since the ./resources/__init__.py does not actually import any of the
modules below it, this trick won't work but just for an experiment,
I'll change the code and try it.
--
Mitko Haralanov mitko at qlogic.com
Senior Software Engineer 650.934.8064
System Interconnect Group http://www.qlogic.com
==========================================
Disraeli was pretty close: actually, there are Lies, Damn lies,
Statistics, Benchmarks, and Delivery dates.
More information about the Python-list
mailing list