Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robdmc/4891e88869593fecfafe9d191d1cf0b1 to your computer and use it in GitHub Desktop.
Save robdmc/4891e88869593fecfafe9d191d1cf0b1 to your computer and use it in GitHub Desktop.
# Some class definition out of your control
class JaredLewis:
def loves(self):
return 'Savage Garden'
# A method you wish the class had
def hates(self):
return "Randy Travis"
# Instantiate the class
jl = JaredLewis()
# Bind methods in increaingly ugly ways
jl.hates = hates.__get__(jl, JaredLewis)
jl.despises = (lambda self: "Rob's hacks").__get__(jl, JaredLewis)
# The HORROR
print(
f'Jared Lewis loves {jl.loves()}. '
f'\nHe hates {jl.hates()}. '
f'\nBut above all he despises {jl.despises()}'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment