Re: except KeyError, everywhere

2011-06-06 Thread Ben Finney
"Gabriel Genellina" writes: > En Fri, 03 Jun 2011 21:02:56 -0300, Nobody escribió: > > > 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: > > > > The general concept is called "m

Re: except KeyError, everywhere

2011-06-06 Thread Gabriel Genellina
En Fri, 03 Jun 2011 21:02:56 -0300, Nobody escribió: 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: The general concept is called "memoization". There isn't an implementation in th

Re: except KeyError, everywhere --> memoization

2011-06-04 Thread Wilbert Berendsen
Hi, Many thanks for everyone's explanations and pointers! thanks! Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listinfo/python-list

Re: except KeyError, everywhere

2011-06-03 Thread Ben Finney
Ben Finney writes: > It's best to implement Memoize as a Python decorator in one place > http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize>. Michele Simionato discusses a better implementation of a Memoize decorator in the documentation for his useful ‘decorator’ library http://micheles

Re: except KeyError, everywhere

2011-06-03 Thread Ben Finney
Wilbert Berendsen writes: > I find myself all over the place associating objects with each other using > dicts as caches: > > something like this: > > _cache = {} > > def get_something(obj): > """Returns the frobnicate-plugin for the specified object.""" > try: > return _cache[ob

Re: except KeyError, everywhere

2011-06-03 Thread Nobody
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 con

except KeyError, everywhere

2011-06-03 Thread Wilbert Berendsen
self.func = func def __missing__(self, key): res = self[key] = self.func(key) return res Are there other peoply using things like this? Is there a solution like this in the standard lib that I'm overlooking? Of course 'except KeyError' everywhere is not re