[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

newb question about @property

Bill wrote:
> Chris Angelico wrote:
>> Decorators are fairly straight-forward if you understand higher-order
>> functions.  <snip>
>> ChrisA
> I was just minding my own business, and thought to write my first 
> decorator for a simple *recursive* function f.  The decorator WORKS if 
> f does not make a call to itself 
> (it really wasn't). 

Using the (PyCharm) debugger, I determined that my inner function that 
was calling my wrapped (Fibonacci sequence) function but wasn't 
returning anything to the invoking environment. I fixed it for the sake 
of a good, if costly, lesson.  Not much of a wrapper, but it "works".  A 
version which merely prints a tab before the function call, instead of a 
row of asterisks produces output which is more interesting to look at.

def wrap(func):
     def inner(*args, **kwargs):
         a= func(*args, **kwargs)
         return a
     return inner