Hacker News new | past | comments | ask | show | jobs | submit login

Ok, fine. Can we have the print statement back?



Genuinely curious, why do you prefer `print` to be a statement rather than a function? I've heard a lot of criticisms of Py3, but this is the first time I've heard this one.


I think a function is "better", but the print statement should have been preserved.

Print is used either for:

1) Writing to stdout/stderr 2) Debugging the hacky way

The print function is better for the former (though more often than not, I use Armin Ronacher's click.echo for compability)[0], but I fastly prefer the print statement for (2). Not dealing with parentheses is always a plus; I can add and remove print statements far more quickly.

I find it to be an increase in friction, and I don't see any real downside in leaving it in.

[0] http://click.pocoo.org/5/api/#click.echo


I agree with you on 1), I much prefer `print(..., file=sys.stderr)` to `print >>sys.stderr, ...`.

For 2), though, I have always used auto-inserting parens in my vim, so I never really experienced any pain w.r.t. parentheses. I can see how that would be a pain, though.


I prefer the print function for debuging, because I can just do s/print/log.debug if I want to demote debug printing to the logger.


I've heard this complaint multiple times actually, though it was just because it's not what people are used to.

I'm fine with leaving it out, but I would like it back in. The reason is that in my mind Python has been the language of simplicity and elegance, where you are constantly pleasantly surprised by the ease of use. Python, to me, is the language of childish glee. The parentheses on the print function is Python putting on a suit and going to work.


I'm fairly new to Python (within just a few years of my first use of it) but have already been hacking at some Py2 apps to update them to Py3 because, well, Unicode. Much (not most, but much) of the random code I've tried to run with Py3 works without actual code modification beyond import statements.

Two primary exceptions: byte/string encoding in Py2, and print. So much of the Py2 syntax works without change in Py3, and while I wholeheartedly agree with "print('foo')" as the proper way to print something, "print 'foo'" is littered all over the random Py2 scripts I've found in my travels.

I am, in fact, converted to print(), for the record. The first time (in Py2) I tried to extrapolate what I learned about (asterisk)args, I attempted to do this:

  print *df.columns
Whoops. Then came Py3:

  print(*df.columns)
Huzzah! Instantly converted.

(edit again: Can't seem to get that asterisk to work without a full-on space)


why do you prefer `print` to be a statement

The best quip I've seen about this is:

   Python 3 broke "hello, world".
I just tried, and the "hello, world" program from K&R still compiles and runs.

The article claimed that Guido started Python back in 1989. Wiki tells me that Python 3 was released in 2008. So, if after nearly 20 years of existence, you break the quintessential program of your (or rather any) computer language, then, ipso facto, you've just abandoned your current language and switched to a new one.

Others have mentioned that the print statement could have been retained, while also allowing a function. I would have preferred that. Not "the Python way" of having one way to do something, but there's also backward compatibility to consider.


I've heard this one many times, but the suggestion is as brainless as it sounds. I'll be surprised if you get anything resembling a decent reason.


in the beginning,

   >>> print "hello world"
was the best marketing slogan for Python's down to earth simplicity versus competitors that one could possible have devised. Not even any brackets!!

It defined the ethos of the language, was the first thing people came across when considering Python for the first time, and probably punched well above its weight in bringing people in.


I never considered the first impression aspect of print statement vs print function.

I feel that simplicity is a driving factor in python's 'virality' from one programmer to the next, and in that context your case is very compelling.


>>> print("hello world")

And that's so much harder to grok?


Short answer: Because the change breaks a lot of code for no reason other than a stylistic one. It wouldn't be difficult for it to be a function, but the interpreter to allow the old invocation.

Though it does serve as a neat diagnostic "this program wasn't built with python3 in mind" message when you encounter the syntax error, so maybe it balances out...


Print as a function is a definite improvement in terms of functionality and API (`print >>fileobj, ...` always looked like syntax from another language). I too though I'd be bothered by the extra (), mainly due to muscle memory, but after spending a week with it, I could hardly feel any inconvenience.

Setting up an abbrev or a snippet also helps. I use these a lot:

    p<tab>   -> print(|)
    pp<tab>  -> import pprint; pprint.pprint(|)


> `print >>fileobj, ...` always looked like syntax from another language

Yes, AWK specifically.




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

Search: