nested - python - list all inner functions of a function? -
In the python you can fname .__ code __. To retrieve the list of co_names
function and global items that reference a function if I fname .__ code __. Co_varnames
, it contains internal functions, I believe.
Essentially the internal .__ code __. Co_names
? 'inner'
looks like starting with a string, as co_vara name
I do not think you can inspect the code object because the internal functions are lazy, and their code-objects are created only in time. You probably want to see the ast module. This is a quick example:
are the result: function1, function2 , F1_var1, very correct name _ or_id = getattr (x, 'name', getattr (x, 'id', none) function 3, f2_war 1, f2_w2, f3_war 1. compulsory disclaimer: There is no good reason to talk .. but have fun :)
Oh, and if you only have internal functions Want a name?
print dictionary (in ast.walk for x [x, name] x (ast.parse (inspect.getsource (some_function))) if type (x) .__ name__ == 'FunctionDef'])
Comments
Post a Comment