Re: Another method of lazy, cached evaluation.

2006-01-18 Thread simonwittber
Hmm, good ideas. I've made some refinements and posted to the cookbook. The refinements allow for multilple function arguments and keywords. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466315 -Sw. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another method of lazy, cached evaluation.

2006-01-18 Thread Kamilche
If you wanted to avoid the __getattr__ __setattr__ speed hit, something like this would work. However, you have to not mind calling a function to get the data, instead of only getting the attribute: class Cache(object): _cache = {} def __init__(self, filename): self.filename = file

Re: Another method of lazy, cached evaluation.

2006-01-18 Thread Kamilche
[EMAIL PROTECTED] wrote: > Now, when the pic_1 and pic_2 attributes are accessed, they will return > an Image instance, which is something different to which they were > initially assigned. Is this kind of behavior bad form? That's pretty good, I like it. > Likewise, what > do people think abou

Another method of lazy, cached evaluation.

2006-01-17 Thread simonwittber
Recently, I needed to provide a number of game sprite classes with references to assorted images. I needed a class to: - allow instances to specify which image files they need. - ensure that a name should always refer to the same image. - only load the image if it is actually used. Af