Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just from __past__ import print_statement

I really hope someone makes this work. I literally laughed and thought that it was a troll the first time I saw the future print import and that being used as a compelling reason that I should switch to Py3.



I don't think print() is what I'd call "compelling", but I for one am quite glad to see this go:

    print "Text",
For those not familiar with Python 2's syntax: that trailing comma is significant. And it's pure syntax; it's not the creation of a tuple either…


It gets weirder in the old syntax when you specify an output stream:

    print >>sys.stderr, "Spam"
Whereas in the new print function it's a keyword argument:

    print("Spam", file=sys.stderr)


It’s awful, especially since you can’t omit the space at the end. But the replacement,

    print(“Text”, end=“”)
is verbose. Not too verbose, but considering how often I write prints as temporary throwaway code, every little bit hurts…


Consistency and keyword args are useful.


"11. There should be one-- and preferably only one --obvious way to do it." from the Zen of Python. Somebody intentionally misread it as, "There should be only one way to do it." They obviously made a grave mistake. Same with many 2->3 changes.


Also from the Zen of Python: "Special cases aren't special enough to break the rules", the old print statement contains a lot of special syntax not found anywhere else in the language. Also "Readability counts", it's really obvious what print("foo", file=sys.stderr, end="") does instead of deciphering a construct like print >>sys.stderr, "foo", . Moreover you can pass a print function around, perform partial application, etc., a statement does not give you that.


You prove nothing about why the two cannot co-exist in a non-regressive way. 'print' as a function already exists in Python 2, providing all the benefits you describe.


I stand very much corrected on the issue of 'print' and retract the above -- it only looks like a function syntactically in special (albeit, the most common) cases; PEP 3105 makes good points on how Python's parsing of whitespaces and parens renders a non-regressive parser out of reach. RTFM, I guess.


The old way was foolishly inconsistent with the rest of the language. It only serves as an small expedient in the REPL.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: