In [15]:
import importlib
from importlib import import_module
from inspect import signature, getmodule
import sys
if not '..' in sys.path:
sys.path.append('..')
In [7]:
engine = importlib.import_module('engine')
In [12]:
def f(x):
return sin(x)/x
In [11]:
from math import sin
In [19]:
exec("globals()", {}, {'f': f})
In [1]:
M = __import__('math', {}, {}, ['sin'], 0)
In [7]:
getattr(M, 'sin')
Out[7]:
In [8]:
def look_up(module, name):
M = import_module(module)
return getattr(M, name)
def function_module_and_name(f):
return getmodule(f).__name__, f.__name__
In [13]:
f = look_up('numpy.random', 'normal')
In [18]:
function_module_and_name(a)
Out[18]:
In [17]:
def a(x):
return f()
In [19]:
look_up('__main__', 'a')
Out[19]:
In [ ]: