Created
January 10, 2022 17:22
-
-
Save robdmc/4891e88869593fecfafe9d191d1cf0b1 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
# 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