[Python-Dev] Py2.6 ideas

Josiah Carlson jcarlson at uci.edu
Sat Feb 17 00:33:23 CET 2007


"Raymond Hettinger" <python at rcn.com> wrote:
> > Raymond Hettinger schrieb:
> >>  d, g, v, t, r = model(somecontract)
> 
> [MvL]
> > I find that line quite unreadable
> 
> Of course, I can't give you the fully spelled-out line from proprietary code.
> But at this point we're just talking about the use cases for tuples with or
> without named attributes.  Some functions return multiple values and
> some calls to those functions do tuple unpacking.  That is ubiquitous
> throughout Python.  If the tuple also happens to be a NamedTuple,
> you get tooltips for it (reminding you which fields are which) and
> any error messages will show the full repr with both the names
> and values.
> 
> If not unpacked, then the attribute access is helpful.  Something
> like contract.vega or testresult.failures or somesuch.

For what it's worth, I've actually been using a similar approach with
lists and global names of list indices because I needed a mutable
structure, the list instance was significantly smaller than an object
with __slots__ (by a factor of 3), and because using global constants
was actually competitive with a __slots__ name lookup.

After having seen your tuple recipe, I've been planning on converting it
to a list-based recipe for the same benefits (except for unpacking) in
my own code.

Then again, I'm also looking forward to adding the tuple-based recipe to
my own library for all of the reasons you outlined.


 - Josiah



More information about the Python-Dev mailing list