Skip to content

Instantly share code, notes, and snippets.

@naquad
Created December 7, 2012 01:44
Show Gist options
  • Save naquad/4230052 to your computer and use it in GitHub Desktop.
Save naquad/4230052 to your computer and use it in GitHub Desktop.
def setup_constants(name, bases, dict):
print name
for idx, i in enumerate(dict['HEADER']):
name = 'COLUMN_' + i.upper().replace(' ', '_')
dict[name] = idx + 1
return type(name, bases, dict)
class Test:
__metaclass__ = setup_constants
HEADER = ['Item', 'Qty', 'Unit price']
def __init__(self):
pass
def t(self):
print self.COLUMN_ITEM
class T2(Test):
HEADER = ['Test', 'Item']
print T2.COLUMN_ITEM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment