I want a enum with predefined single character constants (good for storing in database) and string interpretation. Here is what I am thinking of:
class Fruits(Enum):
APPLE = 'A'
PEAR = 'P'
BANANA = 'B'
def __unicode__(self):
if self == APPLE: return "Crunchy Apple"
if self == PEAR: return "Sweet Pear"
if self == BANANA: return "Long Banana"
But
fruit = Fruits.APPLE
print fruit.__unicode__()
gives
AttributeError: 'unicode' object has no attribute '__unicode__'
And besides there must be a more elegant way of doing it
How to do it better?
sys.versionto be sure.)Fruits.TYPE_APPLEcome from? You only definedFruits.APPLE. If you retyped the code in the question from memory, copy-paste it from a file you've actually run or an actual interactive session next time.