Prev: The real problem with Python 3 - no business case forconversion (was "I strongly dislike Python 3")
Next: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3")
From: Matthew Vernon on 3 Jul 2010 05:15 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 TIA, Matthew -- Rapun.sel - outermost outpost of the Pick Empire http://www.pick.ucam.org
From: Peter Otten on 3 Jul 2010 05:46 Matthew Vernon wrote: > 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 execfile(path) in a module with a fixed name that you can import wherever you need access to your configuration data? Peter
From: Bruno Desthuilliers on 3 Jul 2010 05:06 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.
From: Matthew Vernon on 3 Jul 2010 07:10 Peter Otten <__peter__(a)web.de> writes: > Matthew Vernon wrote: > > > 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 > > execfile(path) > > in a module with a fixed name that you can import wherever you need access > to your configuration data? That looks like what I want, thanks :) Matthew -- Rapun.sel - outermost outpost of the Pick Empire http://www.pick.ucam.org
From: Terry Reedy on 3 Jul 2010 15:02
On 7/3/2010 5:15 AM, Matthew Vernon wrote: > 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 cachestrs=__import__(path,fromlist='cachestrs').cachestrs ? -- Terry Jan Reedy |