I want to override a function internal to some 3rd party code. Here's an example of my intent.
(edit: I've corrected the spelling error below, and now this does work as intended)
#--- dog.py (3rd party code) ---
def _bark():
print("WOOF!")
def make_it_bark():
_bark()
#--- make_catlike.py (my code)---
import dog
dog._bark = lambda: print("MEOW") #<<-- 'bark' in original, so failed!!!!
dog.make_it_bark()
# edit: now prints out "MEOW" instead of "WOOF!" like I want
How do I get the 3rd party dog.py code to use my version of _bark?
[conclusion: This was only failing because of a spelling error. Thanks for the help!!]
In code you provided make sure you have not forgotten underscore when redefining _bark function. If you want to change method of a class, a good idea would be to inherit that class and override method in your class.