loading configuration files that are themselves python

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sat Jul 3 05:06:31 EDT 2010


Matthew Vernon a écrit :
> Hi,
> 
> Is there a more idiomatic way of loading in a configuration file
> that's python code than:
> 
> _temp=__import__(path,fromlist='cachestrs')
> cachestrs=_temp.cachestrs
> 
> ? I mean, that's pretty ugly...Plain "import" doesn't work in this
> case because 'path' is a variable defined elsewhere

At least you have a way to do it, so you should be happy !-)

Another solution would be to add the path to sys.path, but it wouldn't
necessarily be the best thing to do here.



More information about the Python-list mailing list