def myFunc( a, b ):
def innerFunc( c ):
print c
innerFunc( 2 )
print a, b
How can I access the inner function directly? I want the object/address of that function in the format
<function innerFunc at 0xa0d5fb4>
I tried with myFunc._getattr_( 'innerFunc' ) but that didn't work.
As the function does not exists until the function call (and only exists during it), you cannot access it.
If the closure is not important, you can build the inner function directly from the code constant placed inside the outer function:
inner = types.FunctionType(myFunc.__code__.co_consts[1], globals())
The position inside the const values of the function may vary...
This solution does not require calling myFunc
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With