newb question about @property

Bill BILL_NOSPAM at whoknows.net
Tue Oct 3 02:01:28 EDT 2017


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):
 print('*'*20)
 a= func(*args, **kwargs)
 print(a)
 print('*'*20)
 return a
 return inner
Bill


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /