C-style static variables in Python?
ptmcg at austin.rr.com
Fri Apr 2 19:28:13 CEST 2010
On Apr 1, 5:34 pm, kj <no.em... at please.post> wrote:
> When coding C I have often found static local variables useful for
> doing once-only run-time initializations. For example:
Here is a decorator to make a function self-aware, giving it a "this"
variable that points to itself, which you could then initialize from
outside with static flags or values:
from functools import wraps
fn_.__globals__["this"] = fn_
this.counter += 1
foo.counter = 0
More information about the Python-list