Python – Simulate talking enums and bitsflags


“id” of entry is rising 1 by 1 (seen at

def enum(*sequential):
 enums = dict(zip(sequential, range(len(sequential)) ))
return type('Enum', (), enums)


“id” of entry is rising exponentialto power of 2 to allow check for multiple bits

def bitflag(*sequential):
 bitflags = dict(zip(sequential, [2**i for i in range(len(sequential))] ))
 return type('Bitflag', (), bitflags)

Comments are closed.