function with a state

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Mon Mar 7 15:28:25 EST 2005


Reinhold Birkenfeld wrote:

> or with a default function argument:
> 
> 
> class Dummy: pass
> 
> def myFun(globe=Dummy()):
>     try:    globe.globe += 1
>     except: globe.globe = 1
> 
>     return globe.globe

A quicker way:

def myFun(globe=[0]):
    globe[0] += 1
    return globe[0]

Reinhold



More information about the Python-list mailing list