I am attempting to use __import__() to read a Python file. It is not working. 

What is particularly odd is that it works from the interactive prompt. Looking 
at sys.path I can see that in the interactive session path starts with an empty 
entry. Adding a similar entry to my script causes the import to work. Not sure 
why. Any clues?

Here the code:
import sys

try:
    f = __import__("/tmp/my/settings")
    print f.__name__
except:
    print "1. Failed"

sys.path.insert(0, '')

try:
    f = __import__("/tmp/my/settings")
    print f.__name__
except:
    print "2. Failed"



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to