by musicale · 6y ago · 0 comments
print "Hey, they brought back the print statement!"
print("But you can still call the print() function!")
print ("printing", "tuples", "works", "like", "python2")
It would be a massive QoL improvement and also accelerate Python 3 adoption.(I'd actually be OK with allowing keywords to be used as method/function names in general, but that's a more extensive change than
from __past__ import print_statement
)Removing it (and breaking compatibility in general with no easy workarounds) is one of the major footguns in Python 3 that drastically slowed its adoption and basically forked the language.
It's a prime example of ideology trumping usability and practicality, resulting in the waste of probably millions of programmer hours, and orphaning millions of lines of code in Python 2 programs and libraries.
Other languages have managed to evolve effectively for decades without breaking backward compatibility; it's disappointing and embarrassing that Python simply hasn't.
I’ve definitely run into issues 2to3 couldn’t automatically fix (encoding issues in some py2-only lib I needed to use IIRC), but upgrading print doesn’t really have much overhead.
1) it modified the file object's "softspace"
>>> class MyFile(object):
... softspace = "Hello"
... def write(self, s):
... pass
...
>>> f = MyFile()
>>> f.softspace
'Hello'
>>> print >>f, "spam"
>>> f.softspace
0
2) This wasn't a problem until >> was added, because of problem #2 - the print statement didn't originally let you print to anything other than stdout. Which meant that if you wanted to support writing to a file instead of a stdout then you had to re-implement print yourself.In practice, I've also found that having print as a function adds functionality because I can do things like:
print(*data_values, sep="\n")
which is a quick way to print each value in a list on its own line. for v in data_values: print v
Is exactly the same length but much more readable.