您的位置:首页 > 编程语言 > Python开发

python enum 枚举

2017-02-13 09:21 357 查看
http://www.cnblogs.com/codingmylife/archive/2013/05/31/3110656.html

python 3.4+

from enum import Enum
message_type=Enum('message_type','un_read readed deleted')

print(message_type.un_read.value)
print(message_type.readed.value)
print(message_type.deleted.value)

print(dir(message_type.readed))

# 或者
class MessageType(Enum):
un_read = 1
readed = 2
deleted = 3

print(MessageType.deleted.value)

# 1
# 2
# 3
# ['__class__', '__doc__', '__module__', 'name', 'name', 'value', 'value']
# [Finished in 0.2s]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: