question about import

Jonathan Vanasco jonathan at findmeon.com
Wed Jun 11 19:17:40 CEST 2008


I'm a little unclear about import / __import__

I'm exploring dynamically importing modules for a project, and ran
into this behavior

works as expected:
    app = __import__( myapp )
    appModel = __import__( myapp.model )

but...
    appname= 'myapp'
    app = __import__( "%s" % appname )
    appModel = __import__( "%s.model" % appname )

In the latter example, app and appModel will always seem to be
imported as 'myapp' , and I've yet to find a way to address the .model
namespace

I know 'dynamically importing modules' is cursed upon -- and I'm
likely rewriting hundreds of line of codes so I can work around this
with a registration system -- however I'd like to understand why this
occurs and know if what i'm trying is even possible.



More information about the Python-list mailing list