Home >Backend Development >Python Tutorial >Introduction to the simple method of implementing enum function in Python

Introduction to the simple method of implementing enum function in Python

高洛峰
高洛峰Original
2017-03-04 15:59:061441browse

This article mainly introduces the method of Python to simply implement the enum function, and briefly analyzes the related skills of Python to implement the enum function. Friends in need can refer to it

The example of this article tells the simple implementation of the enum function in Python method. Share it with everyone for your reference, the details are as follows:

class Enumerate(object):
  def __init__(self,names):
    for number,name in enumerate(names.split()):
      setattr(self, name, number)
codes = Enumerate('FOO BAR BAZ')
print codes.FOO
codes.FOO = 10
print codes.FOO

For more introduction on how to simply implement the enum function in Python and related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn