python如何获取当前打印_如何获取python打印函数的源代码?

我正在尝试使用inspect获取python打印的源代码,但它正在抛出错误。有人能告诉我如何得到python2.7打印语句的源代码吗。inspect.getsourcefile(print)

---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in ()

----> 1 inspect.getsourcefile(print)

/usr/lib/python3.4/inspect.py in getsourcefile(object)

569 Return None if no way can be identified to get the source.

570 """

--> 571 filename = getfile(object)

572 all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:]

573 all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:]

/usr/lib/python3.4/inspect.py in getfile(object)

534 return object.co_filename

535 raise TypeError('{!r} is not a module, class, method, '

--> 536 'function, traceback, frame, or code object'.format(object))

537

538 ModuleInfo = namedtuple('ModuleInfo', 'name suffix mode module_type')

TypeError: is not a module, class, method, function, traceback, frame, or code object

In [86]: inspect.getsourcefile(builtin.print)

---------------------------------------------------------------------------

NameError Traceback (most recent call last)

in ()

----> 1 inspect.getsourcefile(builtin.print)

NameError: name 'builtin' is not defined

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值