如何返回函数的代码?func_name方法按预期工作,但func_code不起作用。
>>> def testthis(): print 'test successful'
>>> testthis()
test successful
>>> testthis.func_name
'testthis'
>>> testthis.func_code
<code object testthis at 0124D728, file "<pyshell#281>", line 1>发布于 2012-08-10 13:08:42
您可以使用
inspect.getsourcelines(function_name)
因为他得到了密码。
In [1]: def testthis(): print "hello"
In [2]: import inspect
In [3]: inspect.getsourcelines(testthis)
Out[3]: ([u'def testthis(): print "hello"\n'], 1)https://stackoverflow.com/questions/11902253
复制相似问题