If I have a text file that contains a python function definition, how can I make the function call from another Python program. Ps: The function will be defined in the Pytho
compile() and eval() can do the trick:
>>> code = compile('def foo(a): return a*2', '', 'exec') >>> eval(code) >>> foo 52: >>> foo(12) 53: 24
or with file:
with open(filename) as source: eval(compile(source.read(), filename, 'exec'))