我想知道是否有办法打印函数定义?
所以如果我想做这样的事情:
def hello():
print 'hello'
some_function_to_show_definition(hello())
输出应该是:
print 'hello'
只是在 python 中乱搞,我只是想知道:)
最佳答案
inspect
是正确的方法:
In [8]: def foo():
...: print 'hello'
...:
In [9]: import inspect
In [10]: inspect.getsourcelines(foo)
Out[10]: ([u'def foo():\n', u" print 'hello'\n"], 1)
关于python - 有没有办法在Python中打印函数的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23437914/