building string for __import__()
Agent Drek
drek at MonsterByMistake.Com
Tue Dec 14 10:59:47 EST 1999
On Tue, 14 Dec 1999, Adrian Eyre wrote:
|Date: Tue, 14 Dec 1999 10:18:22 -0000
|From: Adrian Eyre <a.eyre at optichrome.com>
|To: Agent Drek <drek at MonsterByMistake.Com>, python-list at python.org
|Subject: RE: building string for __import__()
|
|> ImportError: No module named /mnt/somewhere0/foo1/flub2/TARGET
|
|Assuming PYTHONPATH contains /mnt
|
|import and __import__ take the format: somewhere0.foo1.flub2.TARGET
|
|Although if you want to execute a script, you can use:
|
|execfile("/mnt/somewhere0/foo1/flub2/TARGET")
|
|--------------------------------------------
|Adrian Eyre <mailto:a.eyre at optichrome.com>
|Optichrome Computer Solutions Ltd
|Maybury Road, Woking, Surrey, GU21 5HX, UK
|Tel: +44 1483 740 233 Fax: +44 1483 760 644
|http://www.optichrome.com
|--------------------------------------------
Hmmm...
my problem was that the variable that I built up with:
dirdata = {
'somewhere': '0',
'foo': '1',
'flub': '2'
}
FILE = "/mnt/somewhere" + dirdata['somewhere'] + \
"/foo" + dirdata['foo'] \
"/flub" + dirdata['flub'] \
"/TARGET"
would give me the import error but just typing it manually into the
interpreter would work fine. I'll try the . notation.
>>> c = import__("/typing/in/the/path/by/hand/did/it/TARGET")
execfile(FILE) works well enough however. __import__ just didn't like
my Object FILE.
I'm happy enough with execfile and was just curious about what I was
doing wrong with __import__
thanks,
=derek
Monster By Mistake Inc > 'digital plumber'
http://www.interlog.com/~drek
More information about the Python-list
mailing list