Dekoratörler yalnızca global fonksiyonlara değil bir sınıfın metotlarına da uygulanabilmektedir.
This commit is contained in:
parent
a0ee7632b0
commit
d0465110fa
18
python-temel/sinifin.metotlarina.dekorator.py
Normal file
18
python-temel/sinifin.metotlarina.dekorator.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user