在python中使用inspect.getsource函数查看函数源代码,具体方法如下:
import inspectdef print_hh():print('hh')source = inspect.getsource(print_hh) # 查看自定义函数print_hh的源代码print(source)
import inspect
def print_hh():
print('hh')
source = inspect.getsource(print_hh) # 查看自定义函数print_hh的源代码
print(source)
输出结果为:
def print_hh():print('hh')