Python __future__ 方法
这样说是否正确
__future__.__dict__.keys()
如果“print”没有被列为方法之一,那么我使用的Python版本不提供未来的打印功能, ? (我使用的是Python 2.5.5。)
Would it be correct to say that if 'print' is not listed as one of the methods in
__future__.__dict__.keys()
then the version of Python that I am using does not supply the future print function? (I am using Python 2.5.5.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,但这就是
print_function
,它是在 Python 2.6 中引入的。Right, but that would be
print_function
, and that was introduced in Python 2.6.几乎正确。该功能称为
print_function
,而不是打印。Almost correct. The feature is called
print_function
, not print.是的。这是正确的。
但进行该检查的更好方法是:尝试:
从未来导入 print_function
除了导入错误:
print "print 是一个 stmt"
您不能执行上述导入和检查 print_function 的方法。可用的方法似乎是,检查 sys.version 并检查 __future__ 字典,就像你正在做的那样。
Yes. That is correct.
But a better way to do that check would be:try:
from future import print_function
except ImportError:
print "print is a stmt"
You cannot do the above way of importing and checking for print_function. The ways available seems, checking with sys.version and checking the
__future__
dictionary as you are doing.