Newbie Question: Giving names to Elements of List/Tuple/Dict
Oren Tirosh
oren-py-l at hishome.net
Sat Nov 30 09:26:06 EST 2002
On Sat, Nov 30, 2002 at 02:41:02PM +0100, holger krekel wrote:
> > class record(dict):
> > def __init__(self, initfrom=(), **kw):
> > dict.__init__(self, initfrom)
>
> But this pollutes the instance's namespace.
Do you mean that dict methods without double-underscores? Yes, of you
add a field called 'keys' to a record it will override the 'keys'
method inherited from dict.
> Is inheriting from the dict class really neccessary?
Another way to achieve this effect is overloading __getattr__, __setattr__
but it requires more code and is *much* slower.
Oren
More information about the Python-list
mailing list