Created
February 12, 2017 13:15
-
-
Save AliYmn/186426a557d0644550f5f807894adaa2 to your computer and use it in GitHub Desktop.
decorator_with_arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class decorator_with_arguments(): | |
def __init__(self, arg1, arg2, arg3): | |
""" | |
__init__ kısmı bizim constructor bölümüdür. | |
@decerator_with_arguments(arg1,arg2,arg3) parametrelerini alır. | |
""" | |
print("__init__() Çalıştı ...") | |
# Değişken atamaları yapılır. | |
self.arg1 = arg1 | |
self.arg2 = arg2 | |
self.arg3 = arg3 | |
def __call__(self, f): | |
""" | |
Deceratorün altındaki fonksiyon f değişkenine eşitlenir. | |
Son olarak ise gönderilen return değerlerine eşit olur | |
""" | |
print("__call__() Çalıştı ...") | |
# fonksiyon içindeki argumanlar *args içinde toplandı. | |
def wrapped_f(*args): | |
print("wrapped_f() Çalıştı...") | |
print("Decorator Argumanları:", self.arg1, self.arg2, self.arg3) | |
print("Gönder {}".format(f(*args))) | |
return wrapped_f | |
@decorator_with_arguments("hello", "world", 42) | |
def sayHello(a1, a2, a3, a4): | |
return a1,a2,a3,a4 | |
sayHello("say", "hello", "argument", "list") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment