Created
January 12, 2013 19:32
-
-
Save Nurdok/4520107 to your computer and use it in GitHub Desktop.
Revisions
-
Nurdok created this gist
Jan 12, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ """TODO: A docstring""" class Bean(type): def __init__(cls, name, bases, dct): def init(self, *args, **kwargs): for attr, arg in zip(cls._attrs, args): setattr(self, attr, arg) for name, value in kwargs.iteritems(): setattr(self, name, value) undefined = [] for attr in cls._attrs: try: getattr(self, attr) except AttributeError: undefined.append(attr) if undefined: print undefined raise ValueError('The following arguments are missing: {0}' .format(', '.join(undefined))) setattr(cls, '__init__', init) class Point(object): __metaclass__ = Bean _attrs = ('x', 'y') p = Point(2, 5) print p