I use the Python function execfile() as a simple but flexible way to handle configuration files - basically, the idea is this:
# Evaluate the 'filename' file into the dictionary 'foo'. foo = {} execfile(filename, foo)
This requires my configuration file to have access to the definition of the Bar class. In this simple example, this is trivial; we can simply define foo = {'Bar' : Bar} and not an empty dict. However, in a real example, I have the whole module that I want to download. One obvious syntax for this:
foo = {} eval('from BarModule import *', foo) execfile(filename, foo)
However, I have already imported BarModule into my top-level file, so it seems to me that I should just define foo as a set of things defined by BarModule , without having to go through this chain of eval and import .
Is there a simple idiomatic way to do this?
source share