2024-04-23 19:04:44 发布
网友
我想知道有没有办法打印出函数的定义?你知道吗
所以如果我想做这样的事情:
def hello(): print 'hello' some_function_to_show_definition(hello())
输出应为:
print 'hello'
我只是在玩python,我只是在想:)
inspect就是要走的路:
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)
inspect
就是要走的路:相关问题 更多 >
编程相关推荐