D
david
Traceback (most recent call last):(e-mail address removed) ha scritto:cache = NoneHello everyone,
I have written this small utility function for transforming legacy file
to Python dict:
def lookupdmo(domain):
lines = open('/etc/virtual/domainowners','r').readlines() lines
= [ [y.lstrip().rstrip() for y in x.split(':')] for x in
lines]
lines = [ x for x in lines if len(x) == 2 ] d = dict()
for line in lines:
d[line[0]]=line[1]
return d[domain]
def lookup( domain ):
if not cache:
cache = dict( [map( lambda x: x.strip(), x.split(':')) for x in
open('/etc/virtual/domainowners','r').readlines()])
return cache.get(domain)
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in lookup
UnboundLocalError: local variable 'cache' referenced before assignment
You miss the:
def lookup(domain):
global cache
...
bye