Florian Lindner a écrit : > Hello, > does python have static variables? I mean function-local variables that keep > their state between invocations of the function.
Not directly. But there are ways to have similar behaviour: 1/ the mutable default argument hack: def fun(arg, _hidden_state=[0]): _hidden_state[0] += arg return _hidden_static[0] * 2 2/ using OO: class Fun(object): def __init__(self, static=0): self._state = static def __call__(self, arg): self._state += arg return self._state * 2 fun = Fun() HTH -- http://mail.python.org/mailman/listinfo/python-list