[Python-ideas] Access to function objects

Christopher King g.nius.ck at gmail.com
Sat Aug 6 20:26:15 CEST 2011


Whoops, sent it to the tutors

On Sat, Aug 6, 2011 at 2:24 PM, Christopher King <g.nius.ck at gmail.com>wrote:

>
>
> On Sat, Aug 6, 2011 at 4:10 AM, David Townshend <aquavitae69 at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110806/7a2f8ddb/attachment.html>


More information about the Python-ideas mailing list