Am I the only one who would love these extentions? - Python 3.0 proposals (long)
Andrew Dalke
adalke at mindspring.com
Tue Nov 11 04:01:09 EST 2003
Just to highlight a new suggestion I made that I hadn't seen before,
use eillipsis ("...") at the end of a list assignment to mean "ignore the
rest of
the RHS." This would allow a style of enum definition like
class Keywords:
AND, ASSERT, BREAK, CLASS, CONTINUE, DEF, \
DEL, ELIF, YIELD, ... = itertools.count()
class consts:
A, B, C, ... = itertools.count()
D, E, F, G, H, ... = itertools.count(10)
This could also be used in
calendar.py has
year, month, day, hour, minute, second = tuple[:6]
which would become
year, month, day, hour, minute, second, ... = tuple
and of course for
(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)
in that same file.
HOWEVER, those are effectively the only two places in the top-level
Python lib which would use this construct correctly. There are places
where it can be used incorrectly, because I think changing
OK, BOOM, FAIL = range(3)
into
OK, BOOM, FAIL, ... = itertools.count()
is overkill -- there should be at least 5 elements before this ... is
useful.
and I think changing
FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16
into
FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT, ... = x*x for x in
itertools.count(1)
is just plain stupid.
Therefore I withdraw this proposal, leaving it for contemplation and
posterity's.
Plus, if accepted then should the following be allowed?
..., x, y, z = itertools.count(100) # get the last three elements
a, b, c, ..., x, y, z = itertools.count(100) # get the first three and
last three elements
?
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list