[Python-Dev] Py2.6 ideas

"Martin v. Löwis" martin at v.loewis.de
Fri Feb 16 13:38:04 CET 2007


Nick Coghlan schrieb:
> However, another aspect that occurred to me is that inheriting from 
> tuple has significant practical benefits in terms of speed and memory 
> consumption, at which point it doesn't seem worthwhile to *remove* the 
> indexing capability.

I'm not so sure that inheriting from tuple, and giving it named fields,
has significant speed and memory benefits. In particular for the memory
benefits, you can use __slots__ to achieve the same effects, and more
efficiently so (because it you don't store the tuple length). As for
speed, I would have to see measurements to be convinced it is faster.

> I suppose you *could* write a completely new C-level record class, but 
> given that Raymond's NamedTuple class gets good performance from a 
> Python implementation, rewriting it in C seems like wasted effort.

It wouldn't necessarily be rewriting: In the C API, you have already
the PyStructSequence machinery (see posixmodule.c:stat_result_fields
for an example). It's just that this machinery isn't available to
Python code, yet, and no alternative convenience library is, either
(other than using __slots__, which won't directly give indexed access).

Regards,
Martin


More information about the Python-Dev mailing list