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
1 changed files with 18 additions and 0 deletions
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 a new issue