Created
August 17, 2015 02:50
-
-
Save mw44118/a32cb107995e5c9818c5 to your computer and use it in GitHub Desktop.
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 characters
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