python里使用enum库--通过它的构造函数来创建枚举类型

栏目: Python · 发布时间: 6年前

内容简介:python里使用enum库--通过它的构造函数来创建枚举类型

有时候需要定义一个枚举类型,但不想创建一个新类来继承创建,就可以直接使用它的构造函数来创建一个枚举类型,如下面的例子:

#python 3.6
#蔡军生 
#http://blog.csdn.net/caimouse/article/details/51749579
#
import enum

BugStatus = enum.Enum(
    value='BugStatus',
    names=('fix_released fix_committed in_progress '
           'wont_fix invalid incomplete new'),
)

print('Member: {}'.format(BugStatus.new))

print('\nAll members:')
for status in BugStatus:
    print('{:15} = {}'.format(status.name, status.value))

输出如下:

Member: BugStatus.new

All members:

fix_released    = 1

fix_committed   = 2

in_progress     = 3

wont_fix        = 4

invalid         = 5

incomplete      = 6

new             = 7

构造函数里的参数value是表示枚举类型的名称,names是表示枚举类型里的每项的名称。

深入浅出Numpy

http://edu.csdn.net/course/detail/6149

Python游戏开发入门

http://edu.csdn.net/course/detail/5690

你也能动手修改C编译器

http://edu.csdn.net/course/detail/5582

纸牌游戏开发

http://edu.csdn.net/course/detail/5538 

五子棋游戏开发

http://edu.csdn.net/course/detail/5487

RPG游戏从入门到精通

http://edu.csdn.net/course/detail/5246

WiX安装 工具 的使用

http://edu.csdn.net/course/detail/5207

俄罗斯方块游戏开发

http://edu.csdn.net/course/detail/5110

boost库入门基础

http://edu.csdn.net/course/detail/5029

Arduino入门基础

http://edu.csdn.net/course/detail/4931

Unity5.x游戏基础入门

http://edu.csdn.net/course/detail/4810

TensorFlow API攻略

http://edu.csdn.net/course/detail/4495

TensorFlow入门基本教程

http://edu.csdn.net/course/detail/4369

C++标准模板库从入门到精通 

http://edu.csdn.net/course/detail/3324

跟老菜鸟学C++

http://edu.csdn.net/course/detail/2901

跟老菜鸟学python

http://edu.csdn.net/course/detail/2592

在VC2015里学会使用tinyxml库

http://edu.csdn.net/course/detail/2590

在Windows下SVN的版本管理与实战 

http://edu.csdn.net/course/detail/2579

Visual Studio 2015开发C++程序的基本使用 

http://edu.csdn.net/course/detail/2570

在VC2015里使用protobuf协议

http://edu.csdn.net/course/detail/2582

在VC2015里学会使用 MySQL 数据库

http://edu.csdn.net/course/detail/2672

以上所述就是小编给大家介绍的《python里使用enum库--通过它的构造函数来创建枚举类型》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Spark

Spark

Bill Chambers、Matei Zaharia / O′Reilly / 2017-10-31 / GBP 39.99

Learn how to use, deploy, and maintain Apache Spark with this comprehensive guide, written by the creators of the open-source cluster-computing framework. With an emphasis on improvements and new feat......一起来看看 《Spark》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

html转js在线工具
html转js在线工具

html转js在线工具