Symbolic imports and manipulation of the namespace?

John Bell jbell at iinet.net.au
Wed Mar 27 03:20:03 EST 2002


I should have pointed out that if it is indeed a traditional config file 
  then it might be smarter to parse it.  In this case why not look at 
the ConfigParser module.  It parses files written in Microsoft .INI 
format and is thus comprehensible to a reasonable subset of end users.

John

VanL wrote:

> 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