Dekoratörler yalnızca global fonksiyonlara değil bir sınıfın metotlarına da uygulanabilmektedir.

This commit is contained in:
Mert Gör 🇹🇷 2023-08-05 16:50:18 +03:00
parent a0ee7632b0
commit d0465110fa
No known key found for this signature in database
GPG key ID: 2100A876D55B39B9

View file

@ -0,0 +1,18 @@
def bar(f):
def g(*args, **kwargs):
print('araya girilen kod')
f(*args, **kwargs)
return g
class Sample:
def __init__(self, a):
self.a = a
@bar
def foo(self):
print(self.a)
# foo = bar(foo)
s = Sample(10)
s.foo # Sample.foo(s, 10)