I am new to python and cant understand the decorators concept. I am trying to implement two decorators, one, nonNegative which assumes an arbitrarily long list of integer arguments and throws an Exception if any is less than 0, and another, allCaps, which assumes an arbitrarily long list of string arguments, and capitalizes them. Then, write a simple function to test each, wrap it, and demonstrate that each decorator works.
I have started and have come to this point.
#!/usr/local/bin/python2.7
def NonNegative(inputs):
for i in inputs:
if i<0:
raise exception
def allCaps(inputs2):
for i in inputs2:
a = i.upper()
print a
def inputs
def inputs2():
inputfile = open ("input.txt")
sentence = inputfile.readlines()
words = (sentence[0].split())
return words
NonNegative(inputs)
I would be grateful if someone can explain me the concept of decorators. I tried to understand it but couldn't.