Load three different modules which have the same name
Alex Martelli
aleax at mac.com
Tue Mar 20 11:33:28 EDT 2007
Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
...
> > example i could load Person from Person (in alpha) as, "Person_Alpha"
> > or something like that in sys.modules? not sure how I might do that.
>
> Use the "as" clause when importing; it's almost the same phrase you wrote
> above:
> from alpha.Person import Person as Person_Alpha
> or something like that.
> alpha should be a package, as someone already said.
Right, but the as clause does NOT affect sys.modules -- the entry in
sys.modules will still be sys.modules['alpha.Person']. I doubt this
matters, but since the OP had very specifically askd about "in
sys.modules" I thought it better to clarify.
If you want to make fake entries in sys.modules you need to do that
explicitly,importing sys and assigning to the entry:
sys.modules['veryweird'] = extremely_tricky_stuph
The only purpose of that is to "fool" future "import veryweird"
statements (executed under any circumstances) to use said extremely
tricky stuph. NOT recommended unless you know what you're doing.
Alex
More information about the Python-list
mailing list