以下几种方法来模拟enum:(感觉方法一简单实用) 复制代码 代码如下: # way1 class Directions: up = 0 down = 1 left = 2 right =3 print Directions.down # way2 dirUp, dirDown, dirLeft, dirRight = range(4) print dirDown # way3 import collections dircoll=collections.namedtuple(‘directions’, (‘UP’, ‘DOWN’, ‘LEFT’, ‘