question about import

Jonathan Vanasco jonathan at findmeon.com
Thu Jun 12 18:59:04 EDT 2008


On Jun 11, 1:45 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:

> Is it cursed upon? Didn't know that.
I didn't either.  Until I asked some people how to do it, and was
admonished for even suggesting the concept.


> However, __import__ only gives you the topmost module - in your case myapp.
ah, i didn't know that!  thanks!


> So you need to do it like this (untested):
>
> name = "a.b.c.d"
> mod = __import__(name)
> for part in name.split(".")[1:]:
>      mod = getattr(mod, part)
> print mod

interesting approach.  unfortunately, it raises AttributeError: 'a'
object has no attribute 'b'

i think i'm going to table this approach.  sigh.




More information about the Python-list mailing list