[Python-ideas] Python Users Aren't Perfect

Terry Reedy tjreedy at udel.edu
Mon Dec 12 17:27:08 CET 2011


On 12/12/2011 8:15 AM, Ned Batchelder wrote:

> parens that make a tuple, but a comma." Then why when displaying a tuple
> does Python insist on using parens around it?
>
>  >>> 1, 2, 3
> (1, 2, 3)
>
> I'm not saying it shouldn't, it's a rhetorical question.

Actually, I would agree that it would be better to not mislead by not 
printing the parens unless necessary. (If done from the beginning.)
For something like
 >>> t = 1,2
 >>> l = list(t)
 >>> t,l
((1, 2), [1, 2])

the outer parens are also unnecessary (while the inner ones are needed) 
and make the result less easy to read. But the easiest way to not print 
them would probably be to test the output string after it is constructed 
for beginning with '(' and ending with ')' and strip them off if so.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list