Skip to content

Instantly share code, notes, and snippets.

@IDK9911
Created March 25, 2023 11:13
Show Gist options
  • Save IDK9911/b02294f0cd586c294e70f81d7f13117d to your computer and use it in GitHub Desktop.
Save IDK9911/b02294f0cd586c294e70f81d7f13117d to your computer and use it in GitHub Desktop.
How to work with decorators and Override function in python
def Override(x):
def new_func(*args,**kwargs):
print('>>>>>')
x(*args,*kwargs)
print('------')
return new_func
class Animal():
def __init__(self,name):
self.name=name
def eat(self):
return "eating"
class Dog(Animal):
def __init__(self,name,spots):
Animal.__init__(self,name)
self.spots=spots
@Override
def eat(self):
print("Bow wow!",self.name,"is eating")
bear=Dog("Bear",True)
bear.eat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment