Hey everyone,
I'm wondering how one caches things in python in a manner similar to how a
static variable or class member might in C#. I can only think of an equivalent
in something like a global variable, but is there another? I'm not good enough
yet to think in a manner "pythonic" but I've an inkling that a generator may do
this? This program (where I want to cache a list of factorials once computed)
is what prompted my questions:
f = [1]
def fact(n):
if n == 1:return 1
if(n > len(f)):
for i in range(len(f), n+1):
f.append(i * f[i -1])
return f[n]
print fact(4) #set it up
print fact(3) #pulled from cache
print fact(6) #grow it
____________________________________________________________________________________
Be a better Globetrotter. Get better travel answers from someone who knows.
Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com