I have this configuration file (test_conf.txt):
[function]
exptime1 = |def foo(f):
| result=float(f['a'])
| return result
and this code that works without problem
c = configparser.ConfigParser()
c.read('test_conf.txt')
e1 = compile(c['function']['exptime1'].replace('|', ''), '', 'exec')
exec(e1)
f = {'a':2, 'b':'3'}
print(foo(f))
nevertheless, when I put this inside another function:
def run():
c = configparser.ConfigParser()
c.read('test_conf.txt')
e1 = compile(c['function']['exptime1'].replace('|', ''), '', 'exec')
f = {'a':2, 'b':'3'}
exec(e1)
print(foo(f))
I have this error:
NameError: name foo is not defined
using dir()
the function foo is in the NameSpace but somehow it is not recognized