[Python-ideas] A suggestion for Python 3 vs Python 2

Steven D'Aprano steve at pearwood.info
Tue Nov 12 08:30:57 CET 2013


On Tue, Nov 12, 2013 at 07:44:03PM +1300, Greg Ewing wrote:
> Xuancong Wang wrote:
> >As you know, reading from and writing to IO is a high frequency 
> >operation.
> 
> Actually, no, I don't know that. Thinking about the code I write,
> the proportion of it devoted to textual output is probably less
> than 1%, often far less. So by your argument it should have
> a rather verbose encoding!

I agree strongly! print is simply not important enough to dedicated 
compiler magic to have it behave differently from every other function.

I just picked one random project of mine, and found 23 instances of 
print in 1644 lines of code, or just under 1.4% of lines. In another 
project, I had zero instances of print in 2149 lines. In another 
project, I had 11 instances of the string print, but only 1 was the 
print statement (the rest were in documentation), out of 791 lines, 
approximately 0.1%.

Consistency is far more important than saving a few key strokes. If 
print magically treats parentheses as optional, so that these are the 
same:

print a, b, c, sep="**"
print(a, b, c, sep="**")

people will be confused why print is so special and they can't do the 
same with any arbitrary function:

result = 1 + my_function a, b, c, keyword_argument=42

And of course, there is the problem that leaving out the parentheses 
makes it ambiguous in Python 3. Does this:

my_tuple = (100, 200, print 42, "hello")

print "42" and generate the tuple (100, 200, None, "hello"), or does it 
print "42 hello" and generate the tuple (100, 200, None)?


-- 
Steven


More information about the Python-ideas mailing list