It is impossible.
The function f2
is defined within f1
. It is not defined until f1
has been called.
In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:def f1():
: print( "f1" )
: def f2():
: print( "f2" )
:--
In [2]: f1()
f1
In [3]: f2()
--------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-fdec4c1c071f> in <module>()
----> 1 f2()
NameError: name 'f2' is not defined
In [4]: f1.f2()
--------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-3af025f48622> in <module>()
----> 1 f1.f2()
AttributeError: 'function' object has no attribute 'f2'
It cannot be called outside of f1
, the name f2
is not defined outside the scope of f1
.