defaultdict of arbitrary depth

Carsten Haese carsten at uniqsys.com
Fri Aug 17 00:53:12 EDT 2007


On Thu, 2007-08-16 at 21:27 -0700, Paul McGuire wrote:
> Of course, very short and sweet!  Any special reason you wrote:
>         self.default_factory = type(self)
> instead of:
>         self.default_factory = recursivedefaultdict
> ?

Besides a pathological need to be clever? ;) The former keeps the
recursive relationship intact if you define a class that inherits from
recursivedefaultdict. The latter would create the nested entries of the
derived class as "vanilla" recursivedefaultdicts instead of instances of
the derived class. Whether this would matter in practice is, of course,
a different question.

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list