Symbolic imports and manipulation of the namespace?

VanL vlindberg at verio.net
Tue Mar 26 17:12:09 EST 2002


Hello,

I was recently solving a problem which required that the config file 
(just a python file) lie outside of the pythonpath.  Is it possible to 
do symbolic importation of a module?

For example, I had:

# cfgpath is passed in on the command line
cfgpath = os.path.basename(cfgpath)
sys.path.insert (0, cfgpath)
import sc_cfg     #Hardcoded config module name!


How do you do this:

# cfgpath is passed in on the command line
cfgpath, cfgfile = os.path.split(cfgpath)
sys.path.insert (0, cfgpath)
import cfgfile     #Hardcoded config module name!

So that any file name (ending with .py, of course, but that's another 
matter) could be the configfile?
I tried the above, but I got an ImportError (no module named cfgfile)

Thanks,

Van





More information about the Python-list mailing list