Skip to content

Instantly share code, notes, and snippets.

@teamdandelion
Created May 12, 2013 20:05
Show Gist options
  • Save teamdandelion/5564726 to your computer and use it in GitHub Desktop.
Save teamdandelion/5564726 to your computer and use it in GitHub Desktop.
Composition test
# 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