Toggle

Chris Angelico rosuav at gmail.com
Thu Oct 9 07:55:03 CEST 2014


On Thu, Oct 9, 2014 at 4:39 PM, Rustom Mody <rustompmody at gmail.com> 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?"
>
> In any case that the P in REPL is not *exactly* the same as print
> (or equivalently the distinction between str and repr) makes for some
> intricate noob confusions.
>
> BTW is there some flag that can make them identical?

I haven't used a proprinter since our XL24E died. Never used an
antiprinter, myself.

Here's how to make print() output the repr() of something:

_ORIG_PRINT = print
def print(*args, **kw):
    return _ORIG_PRINT(*(repr(arg) for arg in args), **kw)

But what's the point?

(Also: Have fun backporting that to 2.5, it won't be easy.)

ChrisA



More information about the Python-list mailing list