Created
May 12, 2013 20:05
-
-
Save teamdandelion/5564726 to your computer and use it in GitHub Desktop.
Composition test
This file contains 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
# posted as a comment to this stackoverflow question: | |
# http://stackoverflow.com/questions/16502315/python-how-to-change-a-module-implementation/16502490#16502490 | |
# when the SpottedDog constructor is called, results in infinite recursion | |
class Dog(object): | |
"""docstring for Dog""" | |
def __init__(self, name): | |
self.name = name | |
def growl(self): | |
return "grrrr" + self.name + "grrr" | |
class SpottedDog(object): | |
def __init__(self, dog): | |
self._internal = dog | |
#self.spots = 3 | |
def __getattr__(self, attr): | |
getattr(self._internal, attr) | |
def __setattr__(self, attr, value): | |
setattr(self._internal, attr, value) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment