Running external module and accessing the created objects

Chris Angelico rosuav at gmail.com
Sat Mar 9 06:47:52 EST 2013


On Sat, Mar 9, 2013 at 10:05 PM, Kene Meniru <Kene.Meniru at illom.org> wrote:
> I have tried importing "user.py" and/or "app.py". However there is no
> single command to call.

I haven't followed the thread in detail, but I gather you're trying to
import a file with a variable name? Instead of 'import user', try:

user = __import__("foobar")

You can then replace the quoted string with whatever you need (note,
leave off the .py extension). In your code, it'll be as if you did:

import foobar as user

but with the flexibility of using whatever run-time-chosen name you need.

ChrisA



More information about the Python-list mailing list