I would like to load a
predicate_function=func line : <return true or false>
You just need to be able to dynamically specify the imports and then dynamically get at the variables.
Let's say your config file is bar.py and looks like this:
x = 3 y = 4 def f(x): return (x<4)
Then your code should look like this:
import sys # somehow modnames should be a list of strings that are the names of config files # # you can do this more dynamically depending on what you're doing modnames = ['bar'] for modname in modnames: exec('import %s' % modname) for modname in modnames: mod = sys.modules[modname] for k in mod.__dict__: if k[:2] != '__': print modname, k, mod.__dict__[k]
I get this output:
bar f <function f at 0x7f2354eb4cf8> bar x 3 bar y 4
Then you at least have all the variables and functions. I didn't quite get what you wanted from the predicate functions, but maybe you can get that on your own now.