Dictionary Enhancement?

Emile van Sebille emile at fenx.com
Thu Oct 31 11:30:08 EST 2002


Rich Harkins:
> Not quite - __makeitem__ will be called (and its value generated)
> whether it needs to be or not - this is my basic objection to
> setdefault() as an approach.  I did reply to myself with an example
> Python class but I guess I would really like to see this become either
a
> default built-in behavior or a separate, but built-in, C type to
manage
> this sort of thing.  The pure Python version will have poor
performance
> characteristics if __getitem__ is called frequently.
>


Did you see Pearu Peterson's post of his lazy dict module?  It says, in
part:

"lazy" mode means that the following statement
    dict[<name>] = func(<name>)
is executed whenever dict has no key <name>.

Here's the ref:
http://groups.google.com/groups?selm=Pine.LNX.4.10.10012310238260.2303-1
00000%40kev.ioc.ee

--

Emile van Sebille
emile at fenx.com

---------







More information about the Python-list mailing list