UserDict and items()

Remco Gerlich scarblac at pino.selwerd.nl
Sat Mar 10 18:40:45 EST 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...
>     [snip]
> > 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,
> put
> > 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...

-- 
Remco Gerlich



More information about the Python-list mailing list