温馨提示×

怎么看python函数源代码

九三
247
2021-02-23 09:51:22
栏目: 编程语言

怎么看python函数源代码

在python中使用inspect.getsource函数查看函数源代码,具体方法如下:

import inspect

def print_hh():

print('hh')

source = inspect.getsource(print_hh) # 查看自定义函数print_hh的源代码

print(source)

输出结果为:

def print_hh():

print('hh')

0