我注意到,在使用from __future__ import print_function
导入新的python函数后,我不能对它使用flush。在我的旅程中,我发现我甚至不能检查它需要什么参数。为什么?在
以下是我所做的:
from __future__ import print_function
import inspect
def f(a, b=1):
pass
#print( print_function )
print( inspect.getargspec( f ) )
g = print
print('what is print: ', print)
print('what is g=print: ', g)
print( inspect.getargspec( g ) )
#print( inspect.getargspec( print ) )
#print('Hello', flush=True)
一切都通过了除了检查指纹:
^{pr2}$为什么会这样?在
这是我的系统的一些信息:
Python 2.7.11 (default, Jun 24 2016, 21:50:11)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
在3.3中,
flush
关键字被添加到print()中。在C函数通常不携带内省所需的信息。这只是C如何定义和编译的一个事实。作为替代,签名被添加到它们的docstring中。如果inspect不工作,空闲的调用提示将返回到docstring。在
在3.4中,增加了一个新的机制来包含一个具有C编码功能的签名属性。新的检验人签字在场时使用。一些C编码的函数已经被转换为包含新的属性,而很多没有。在
摘自signature:
我已经发布了签名文档,因为inspect.getargspec从3.0开始就不推荐使用了
相关问题 更多 >
编程相关推荐