enums - IronPython中是否有类似于ENUM的东西
问题描述
我正在为使用 IronPython(Python 脚本引擎版本 2.7.0.40)的技术程序(ANSYS ACT)编写自定义脚本
在使用标准 CPhython 时,我经常使用 Enum 模块来使选项更具可读性。像这样的东西:
from enum import Enum, auto
class StressType (Enum):
ElemMean = auto()
NodeAveraged = auto()
ElemNodeUnaveraged = auto()
def doSomething (stress, stresstype):
if not isinstance(stresstype, StressType): # Type checking
raise TypeError('Type Error')
if stresstype is StressType.ElemMean:
do something with stress ...
elif (stresstype is StressType.NodeAveraged):
do something else with stress
...
但是,在自定义环境中,此模块似乎不存在。我收到此错误消息:
Starting Python script engine version 2.7.0.40 for extension xxx.
No module named enum
Ironpython 有类似枚举数据类型的东西吗?最好是本机数据类型,因此不必安装任何模块。
谢谢和欢呼。
解决方案
aenum库1除了提供比 stdlib 枚举库更多的功能外,还适用于 Python 2.7 和3.3+
--
1披露:我是Python stdlibEnum
、enum34
backport和Advanced Enumeration ( aenum
) 库的作者。
推荐阅读
- magento-1.9 - 如何使用 Whatsapp 发送 Mag::Log 错误?
- java - 使现有 API 更加 RESTful
- angular - angular 6 d3 可折叠树仅在数据更改时更新文本
- java - 在 TextureView 上录制来自 rtsp 的视频
- sql-server - DB2 中的查询问题
- actions-on-google - 我的谷歌操作已部署,但在谷歌助手中使用时仍显示测试版本
- node.js - 如何在某些应用程序上实现基于用户的权限?
- python-3.x - 读取文件时跳过带有奇怪字符的行
- c# - 无法使用c#从Excel文件中删除空行
- java - 错误未从被调用服务传播到调用者服务