[Python-Dev] Re: accumulator display syntax

Terry Reedy tjreedy at udel.edu
Fri Oct 17 14:17:50 EDT 2003


"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:200310171903.42578.aleaxit at yahoo.com...
> On Friday 17 October 2003 06:38 pm, Skip Montanaro wrote:
>    ...
> >     Alex> ... just as e.g. foo[ 'va':23:2j,
{'zip':'zop'}:45:(3,4) ] ...
> >
> > I have absolutely no idea how to interpret this.  Is this existing
or
> > proposed Python syntax?
>
> Perfectly valid and current existing Python syntax:
>
> >>> class F(object):
> ...   def __getitem__(self, x): return x
> ...
> >>> foo=F()
> >>> foo[ 'va':23:2j, {'zip':'zop'}:45:(3,4) ]
> (slice('va', 23, 2j), slice({'zip': 'zop'}, 45, (3, 4)))
>
> Not particularly _sensible_, mind you, and I hope nobody's yet
> written any container that IS to be indexed by such tuples of
> slices of multifarious nature.  But, indexing does stretch quite
> far in the current Python syntax and semantics (in Python's
> *pragmatics* you're supposed to use it far more restrainedly).

In your commercial programming group, would you accept such a slice
usage from another programmer, especially without prior agreement of
the group?  Or would you want to edit,  as you would with 'return x<y
and True or False' and might with 'return x<z and 4 or 2'?  If you
would reject it in practice, then it is hardly an argument for
something arguably even odder.

Terry J. Reedy






More information about the Python-Dev mailing list