[Steven Bethard]
> * Should default_factory be an argument to the constructor? The three
> answers I see:
>
> - "No." I'm not a big fan of this answer. Since the whole point of
> creating a defaultdict type is to provide a default, requiring two
> statements (the constructor call and the default_factory assignment)
> to initialize such a dictionary seems a little inconvenient.
You still have to allow assignments to the default_factory attribute to allow
the factory to be changed:
dd.default_factory = SomeFactory
If it's too much effort to do the initial setup in two lines, a classmethod
could serve as an alternate constructor (leaving the regular contructor fully
interchangeable with dicts):
dd = defaultdict.setup(list, {'k1':'v1', 'k2:v2'})
or when there are no initial values:
dd = defaultdict.setup(list)
Raymond
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com