I\'ve got this piece of code:
#!/usr/bin/env python
def get_match():
cache=[]
def match(v):
if cache:
return cache
cache=[v]
return ca
Replace
cache=[]
def match(v):
with
def match(v,cache=[])
Explanation: Your code declares cache as a variable of get_match, which the returned match(v) knows nothing about (due to the following assignment). You do however want cache to be part of match's namespace.
I know this way a "malevolent" user could redefine cache, but that's their own mistake. Should this be an issue though, the alternative is:
def match(v):
try:
if cache:
return cache
except NameError:
cache = []
...
(See here)