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
if issubclass(x,int): pass
else: return 'invalid values'
global name 'x' is not defined
Your decorator should look like:
def wrapper(func): def inner(x, y): # inner function needs parameters if issubclass(type(x), int): # maybe you looked for isinstance? return func(x, y) # call the wrapped function else: return 'invalid values' return inner # return the inner function (don't call it)
issubclassexpects a class as first argument (you could replace it with a simple try/except TypeError).
You can find a good explanation of decorators here.