gpt4 book ai didi

python - 枚举行为与 Python 之间的区别

转载 作者:太空宇宙 更新时间:2023-11-04 10:22:00 25 4
gpt4 key购买 nike

这是我的 Ubuntu 笔记本电脑上的 Python 2.7.6:

(myenv)$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> class Fruit(enum.Enum):
... apple=1
... orange=2
...
>>> Fruit.apple
<Fruit.apple: 1>
>>> type(Fruit.apple)
<enum 'Fruit'>

这是在 Heroku 上(也是 2.7.6):

~ $ python
Python 2.7.6 (default, Jul 15 2014, 15:38:10)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> class Fruit(enum.Enum):
... apple=1
... orange=2
...
>>> Fruit.apple
1
>>> type(Fruit.apple)
<type 'int'>

编辑:我的 requirements.txt 文件包含这一行:

enum==0.4.4

这确实会导致问题,因为我的生产版本显示出本地版本没有的错误!

最佳答案

看起来你的 ubuntu 版本是 enum34 backport ,而 heroku 版本是较旧的 enum 包。

如果我没看错你的问题,并且带有 enum34 的版本工作正常,请更改你的需求文件以改为使用它。

关于python - 枚举行为与 Python 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31735062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com