使用Python2.7导入枚举文件不兼容

2024-09-27 21:28:16 发布

您现在位置:Python中文网/ 问答频道 /正文

“我正在运行一个python问题,我正在运行一个枚举文件:

Traceback (most recent call last):

File "lowest_common_ancestor.py", line 4, in <module>
    from test_framework import generic_test, test_utils

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/generic_test.py", line 6, in <module>
    from test_framework.generic_test_handler import GenericTestHandler

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/generic_test_handler.py", line 5, in <module>
    from test_framework.binary_tree_utils import assert_equal_binary_trees, is_object_tree_type

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/binary_tree_utils.py", line 5, in <module>
    from test_framework.test_failure import TestFailure, PropertyName

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/test_failure.py", line 2, in <module>    
from enum import Enum, auto

ImportError: cannot import name 'auto'

我知道我有Python2.7,而“import Enum”只存在于python3中,但是我在如何创建两个不同的环境时遇到了困难,其中我同时拥有python2.7和python3。如何在macunix终端上实现这一点,我也不太熟悉。在


Tags: infrompytestimportlineframeworkusers
2条回答

或者你自己这样做:

# Implement the auto feature that becomes available in 3.6
autoinc = 0
def auto():
    global autoinc
    autoval = autoinc
    autoinc += 1
    return autoval

class AppState(Enum):
    SPLASH = auto()
    STATUS = auto()
    QRCODE = auto()
    FIREWORKS = auto()
    MESSAGES = auto()

auto直到python3.6才出现,并且不在enum34后台端口中。如果您想要2/3兼容的代码,则需要使用^{}1。在

我对macunix终端没有任何经验。在


1公开:我是Python stdlib ^{}^{} backport和{a4}库的作者。在

相关问题 更多 >

    热门问题