Mam dwie klasy jedno rodzica i inne dziecko.Dodawanie dodatkowych funkcji do metody klasy nadrzędnej bez zmiany jej nazwy
class Parent(object):
def __init__(self):
#does something
def method_parent(self):
print "Parent"
class Child(Parent):
def __init__(self):
Parent.__init__(self)
def method_parent(self):
print "Child"
Po dziedziczenie rodzica Chcę zmodyfikować metodę Parent method_parent
zachowaniem oryginalnego funkcjonalność tej metody i dodając kilka dodatkowych linijek kodu do tej metody.
wiem, że mogę stworzyć nową metodę jak
def method_child(self):
self.method_parent()
#Add extra lines of code to perform something
Ale chcę używać oryginalnej nazwy metody. Nie mogę skopiować źródło dla tej metody, ponieważ metoda ta jest z C
modułu
co chcę osiągnąć jest coś takiego
def method_parent():
#do parent_method stuff
#do extra stuff
Czy to w ogóle możliwe?