Toggle

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Oct 10 09:18:07 CEST 2014


Rustom Mody wrote:

> On Thursday, October 9, 2014 10:26:41 AM UTC+5:30, Steven D'Aprano wrote:
>> On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:
> 
>> >>>> Color.Red
>> >>>> print (Color.Red)
>> > Color.Red
>> > # Not sure what to make of that distinction...
> 
>> That's because the interactive interpreter displays the repr() of objects
>> (except for None, which it suppresses), while print outputs the str() of
>> them.
> 
> Yeah...
> 
> What I meant to wonder upon was: "Is this behavior what the pro-print or
> the anti-print folks like?"

Python's print is a tool, not a political party or religion. I'm no
more "pro-print" than I'm "pro-len" and "anti-float". I use it when
appropriate, and don't use it when it isn't.


> In any case that the P in REPL is not *exactly* the same as print

The "P" in Read Eval Print Loop no more stands for Python's print function
(or statement, in 2.x) than the "R" stands for Perl's read(), the "E" for
Lisp's eval, or the L for, um, whatever concrete example of a function
called "loop" we can come up with. It's a generic term that describes the
actions of the interactive environment, not the specific semantics used.


> (or equivalently the distinction between str and repr) makes for some
> intricate noob confusions.

I've been reading this mailing list / newsgroup, and the tutor mailing list,
for over a decade, and I don't recall ever seeing a newbie confused by the
difference between str() and repr(), or why print uses one and the
interactive interpreter the other. I've seen the odd question about it, but
I wouldn't call it "confused". 

That's not to say that it categorically never happened. I'm sure that
*somewhere* there is somebody who is confused. There probably is one or two
newbies out there who lie awake at night wondering why the output of print
looks different from the output in the interactive interpreter. But I do
not believe that this is a widespread problem.


-- 
Steven




More information about the Python-list mailing list