导入为

时间:2016-07-26 09:47:50

标签: python

当我尝试在默认参数中使用导入的__version_info时,它会失败,任何想法我应该如何引用它?

from sys import version_info as __version_info

class Foo:
    def __init__(self, name = "pepe" if __version_info[0] < 3 else "jose"):
        self.name = name

这是错误

Traceback (most recent call last):
File "/home/jose/Documents/Test.py", line 4, in <module>
    class Foo:
File "/home/jose/Documents/Test.py", line 5, in Foo
    def __init__(self, name = "pepe" if __version_info[0] < 3 else "jose"):
NameError: name '_Foo__version_info' is not defined

0 个答案:

没有答案