[Python-Dev] Replacement for print in Python 3.0
p.f.moore at gmail.com
Fri Sep 2 21:45:05 CEST 2005
On 9/2/05, Steven Bethard <steven.bethard at gmail.com> wrote:
> Sorry for the confusion. I wasn't trying to imply anyone was a newbie
> here, only that the earlier messages in this thread suggested that
> these were the print statement's main audience.
No problem - I was more joking than serious. But I don't see the same
implication in earlier messages as you do - to me, the general
impression is that people use the print statement in many different
ways, and debugging and trivial scripts are far from the only use.
> Obviously print is used by the rest of us too -- I count around
> 5000 instances in my installation.
I find it hard to reconcile that with your comment that
newbies/debigging are the only real uses for the print statement...
> However, I only count around 400
> instances where a "print" line ends with a comma.
Yes, generally my uses of print are to produce complete lines of output.
> I understand that. I'd just like to see the opinions backed up with
> real code. ;-) Personally, I still use print a fair bit for debugging
> purposes. But as I don't use it for much else, I can't judge too well
> what other needs people have for it.
Fair enough. I'll try to review where I use the print statement:
- Debugging, most definitely. Adding a quick print "a =", a is often
all that's needed.
- Logging, sometimes. When I just want some basic output, and don't
want to deal with the complexity of the logging package.
- Unix-style command-line utilities, where textual output to stdout is the norm.
- Error and help messages, often with print >>sys.stderr
(The last two are obviously the ones I'd emphasize most when arguing
that print should stay).
Frankly, pretty much anything where the output is to go to
stdout/stderr (console, redirected file or pipe) and it's
line-oriented in nature. Yes, a stream.writeln() method could do what
I want, but the print statement just *feels* more natural.
Interestingly enough, the other languages I use most (C, Java,
functions for output. Except for C, I uniformly dislike the resulting
code - the output structure gets hopelessly lost under the weight of
string concatenation and explicitly added spaces. With C, this is
mitigated by printf, which implies to me that if Python goes this
route, C-style string formatting will become far more prevalent in
But I'm really still just speculating. No-one's really going to know
if it's a bad idea until it happens. Personally, I'm just arguing
against taking that risk in the absence of any clear benefits beyond
More information about the Python-Dev