Initial commit
This commit is contained in:
23
Solutions/6_2/structure.py
Normal file
23
Solutions/6_2/structure.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# structure.py
|
||||
|
||||
import sys
|
||||
|
||||
class Structure:
|
||||
_fields = ()
|
||||
|
||||
@staticmethod
|
||||
def _init():
|
||||
locs = sys._getframe(1).f_locals
|
||||
self = locs.pop('self')
|
||||
for name, val in locs.items():
|
||||
setattr(self, name, val)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name.startswith('_') or name in self._fields:
|
||||
super().__setattr__(name, value)
|
||||
else:
|
||||
raise AttributeError('No attribute %s' % name)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%s)' % (type(self).__name__,
|
||||
', '.join(repr(getattr(self, name)) for name in self._fields))
|
||||
Reference in New Issue
Block a user