Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!shaftesbury.zen.co.uk.POSTED!not-for-mail From: Nobody Subject: Re: except KeyError, everywhere Date: Sat, 04 Jun 2011 01:02:56 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 16 Organization: Zen Internet NNTP-Posting-Host: c838e922.news.zen.co.uk X-Trace: DXC=HcnjQJ^jn;7UF9Yg6^So:5nok4Z\OSV:6QOMCU8L]Sh7LT=EXC7UMW; X-Complaints-To: abuse@zen.co.uk Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6983 On Fri, 03 Jun 2011 22:08:16 +0200, Wilbert Berendsen wrote: > I find myself all over the place associating objects with each other using > dicts as caches: > Are there other peoply using things like this? Is there a solution like > this in the standard lib that I'm overlooking? The general concept is called "memoization". There isn't an implementation in the standard library, but you'll find plenty of examples, e.g. (from the first page of Google hits for "python memoization"): http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize http://code.activestate.com/recipes/52201-memoizing-cacheing-function-return-values/ http://code.activestate.com/recipes/577219-minimalistic-memoization/