Introduction to the simple method of implementing enum function in Python

高洛峰
Release: 2017-03-04 15:59:06
Original
1403 people have browsed it

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
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template