Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Choices without metaclass
import inspect
#y
class Choice(object):
def __init__(self):
self._data = []
for name, value in inspect.getmembers(self):
if not name.startswith("_") and not inspect.isfunction(value):
if isinstance(value,tuple) and len(value) > 1:
data = value
else:
data = (value, " ".join([x.capitalize() for x in name.split("_")]),)
self._data.append(data)
setattr(self, name, data[0])
def __iter__(self):
for value, data in self._data:
yield value, data
class Foo(Choice):
A = 1
B = 2
C = 3, 'CEEEE'
print 'list(Foo()) :', list(Foo())
# [(1, 'A'), (2, 'B'), (3, 'CEEEE')]
print 'Foo().C :', Foo().C
# 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.