[Python-ideas] Different interface for namedtuple?

Antoine Pitrou solipsis at pitrou.net
Fri Mar 4 12:59:15 CET 2011


On Thu, 3 Mar 2011 22:32:13 -1000
"Carl M. Johnson"
<cmjohnson.mailinglist at gmail.com> wrote:
> >>>
> >>> # The custom dictionary
> ... class member_table:
> ...    def __init__(self):
> ...       self.member_names = []
> ...
> ...    def __setitem__(self, key, value):
> ...       self.member_names.append(key)
> ...
> ...    def __getitem__(self, key):
> ...       self.member_names.append(key)

IMO, this looks like too much magic for a stdlib class.
Especially the __getitem__ which will remember any reference made from
within the class definition, at the risk of surprising behaviour.

Also, your notation is actually less powerful, since you can't define
anything else than members with it (you can't add any methods or
properties to your namedtuple-derived class, except by subclassing it
even further).

Regards

Antoine.





More information about the Python-ideas mailing list