what you can do is either return the function or attach it to its parent object when called ...
>>> def myFunc( a, b ): ... def innerFunc( c ): ... print c ... innerFunc( 2 ) ... myFunc.innerFunc = innerFunc ... print a, b ... >>> >>> myFunc(1,2) 2 1 2 >>> myFunc.innerFunc(3) 3 >>>
although, apparently, you can access the source code using a special attribute that has function objects ... myFunc.func_code , although it seems that this is access to some serious materials
>>> help(myFunc.func_code) Help on code object: class code(object) | code(argcount, nlocals, stacksize, flags, codestring, constants, names, | varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]]) | | Create a code object. Not for the faint of heart. |
source share