Re: [Python-ideas] Access to function objects
Aug. 6, 2011
8:26 p.m.
Whoops, sent it to the tutors On Sat, Aug 6, 2011 at 2:24 PM, Christopher King <g.nius.ck@gmail.com>wrote:
On Sat, Aug 6, 2011 at 4:10 AM, David Townshend <aquavitae69@gmail.com>wrote:
def counter(add) as func: if not hasattr(func, 'count'): func.count = 0 func.count += 1 print(func.count)
You already can do that without an as statment.
def counter(add): if not hasattr(counter, 'count'): counter.count = 0 counter.count += 1 return counter.count counter('You ever notice how this parameter is never used anyway?') Output: 1 counter('Oh well') Output: 2
5285
Age (days ago)
5285
Last active (days ago)
0 comments
1 participants
participants (1)
-
Christopher King