importing module as filename

Peter Hansen peter at engcorp.com
Tue Nov 11 16:08:36 CET 2003


david farning wrote:
> 
> I am having a problem with name space contention.
> I am combining two existing programs both with their own config
> modules.
> 
> I have been expermenting with
> import config #grab first config
> sys.path.insert(0,"/usr/share/yum/")
> import config as yconfig #grab second config
> 
> The first config always seems to squash the second config.
> There should be a yconfig.yumconf but there is not.

Working from the names alone, you might find it easier
to simply execfile() the scripts.  If they do nothing more
than define a bunch of constants or something like that, this
should be sufficient to avoid the problem you've seen.

Otherwise the "del sys.modules[config]" approach would seem
the most expedient, if ugly.

-Peter




More information about the Python-list mailing list