Created
August 19, 2015 01:03
-
-
Save ErisianArchitect/ddd8c32c9c627938d9bc to your computer and use it in GitHub Desktop.
This file contains 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
#Testing out decorators | |
class decor: | |
def __init__(self, value_): | |
self.v = value_ | |
def __call__(self, f): | |
def wrapped_(*args): | |
if 'n' in globals(): | |
tmp = globals()['n'] | |
globals()['n'] = self.v | |
f(*args) | |
globals()['n'] = tmp | |
else: | |
globals()['n'] = self.v | |
f(*args) | |
del globals()['n'] | |
return wrapped_ | |
class C: | |
def __init__(self): | |
self.variable = "self.variable" | |
def decora(f): | |
def wrapper_(self, *args, **kwargs): | |
print(self.variable) | |
f(self, *args, **kwargs) | |
return wrapper_ | |
@decora | |
def d_test(self): | |
print("Done") | |
@decor("Tryed") | |
def test(): | |
print(n) | |
n = "Goodbye" | |
try: | |
test() | |
except: | |
print("Error") | |
print(n) | |
try: | |
myC = C() | |
myC.d_test() | |
except: | |
print("Error") | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment