Question about defaultdict
Frank Millman
frank at chagford.com
Sat Feb 23 05:49:37 EST 2013
On 23/02/2013 12:13, Frank Millman wrote:
> Hi all
>
> I use a dictionary as a cache, and I thought that I could replace it
> with collections.defaultdict, but it does not work the way I expected
> (python 3.3.0).
>
[...]
>
> from collections import defaultdict
> my_cache = defaultdict(fetch_object)
> my_obj = my_cache['a']
>
> It does not work, because fetch_object() is called without any arguments.
Thanks, Chris and Peter. Some nice ideas to choose from :-)
Frank
More information about the Python-list
mailing list