Skip to content

Instantly share code, notes, and snippets.

@mw44118
Created August 17, 2015 02:50
Show Gist options
  • Save mw44118/a32cb107995e5c9818c5 to your computer and use it in GitHub Desktop.
Save mw44118/a32cb107995e5c9818c5 to your computer and use it in GitHub Desktop.
class Centipede(object):
def __init__(self):
self.legs = list()
self.stomach = list()
def __call__(self, val):
self.stomach.append(val)
def __str__(self):
return ",".join(self.stomach)
def __setattr__(self, slot, val):
if slot in ["legs", "stomach"] and slot not in self.__dict__:
self.__dict__[slot] = val
elif slot in ["legs", "stomach"] and slot in self.__dict__:
raise AttributeError("sorry, can not assign {0}".format(slot))
elif slot not in ["legs", "stomach"]:
self.__dict__[slot] = val
self.legs.append(slot)
def __repr__(self):
return ",".join(self.legs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment