A function is another object in Python and can be introduced.
You can get the external organ of the function at run time and parse / eval it to make the function available in the current namespace.
>>> import inspect >>> def outer(): def inner(): print "hello!" >>> inspect.getsourcelines(outer) ([u'def outer():\n', u' def inner():\n', u' print "hello!"\n'], 1)
This is actually not the same as calling external.inner (), but if you are not making the inner function explicitly accessible outside the scope of the outer function, I think this is the only possibility.
For example, a very naive attempt at eval might be:
>>> exec('\n'.join([ line[4:] for line in inspect.getsourcelines(outer)[0][1:] ])) >>> inner() hello!
source share