在python中使用inspect.getsource函数查看函数源代码,具体方法如下:
import inspect
def print_hh():
print('hh')
source = inspect.getsource(print_hh) # 查看自定义函数print_hh的源代码
print(source)
输出结果为:
def print_hh():
print('hh')
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python怎么看函数说明