python在函数中有static变量吗
python在函数中有static变量吗
没有直接的static变量
用下面的方式模拟
1 defstatic_vars(**kwargs):
    defdecorate(func):
        fork inkwargs:
            setattr(func, k, kwargs[k])
        returnfunc
    returndecorate
 
@static_vars(counter=0)
deffoo():
    foo.counter  =    print"Counter is %d"%foo.counter