UserDict and items()
scarblac at pino.selwerd.nl
Sun Mar 11 00:40:45 CET 2001
Alex Martelli <aleaxit at yahoo.com> wrote in comp.lang.python:
> "Remco Gerlich" <scarblac at pino.selwerd.nl> wrote in message
> news:slrn9aed8i.cg1.scarblac at pino.selwerd.nl...
> > The cuteness introduced in later Python versions would allow that to be:
> > def __getitem__(self, key):
> > return self.data.setdefault(key, DatabaseCall(key))
> > Ie, look up everything in the database that's not in the dictionary yet,
> > it in, and return what's in the dict.
> Unfortunately, this approach is not lazy -- DatabaseCall is here
> being called also for keys which ARE already among those of self.data.
> A more explicit expression is needed to allow the laziness.
Wow, what an oversight. Of course, that defeats the whole purpose of the
code, thanks for catching it...
More information about the Python-list