I'm trying to learn Decorators . I understood the concept of it and now trying to implement it.
Here is the code that I've written
The code is self-explanatory. It just checks whether the argument passed in int
or not.
def wrapper(func):
def inner():
if issubclass(x,int): pass
else: return 'invalid values'
return inner()
@wrapper
def add(x,y):
return x+y
print add('a',2)
It's throwing error saying global name 'x' is not defined
. I understand that it is not defined under inner
, but didnt know how to rectify this code? Where I'm going wrong?