In python 2.7, what's the best / easiest / most "pythonic" way to convert an integer value to the name of a module-scoped constant with that value?
Bonus points if there's a way to scope the search for variable names to those beginning with a magic prefix.
In other words:
EVT_FOO =0x0001
EVT_BAR =0x0002
EVT_SPAM=0x0004
EVT_EGGS=0x0008
def getEvtName( val ):
""" This should return 'EVT_FOO' when given the number 0x1 """
pass
I know I could just create a dictionary to do a reverse-lookup, but I'd like to think there's a better way in Python. Suggestions?