Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78951

Re: Toggle

Newsgroups comp.lang.python
Date 2014-10-10 07:24 -0700
References (1 earlier) <mailman.14703.1412818949.18130.python-list@python.org> <64c26ed7-33cc-4be9-93ac-8d2b84b92451@googlegroups.com> <5436157d$0$12918$c3e8da3$5496439d@news.astraweb.com> <8dba70e4-9670-40d3-9a3f-d2b593d52ac6@googlegroups.com> <5437882f$0$13012$c3e8da3$5496439d@news.astraweb.com>
Message-ID <39f1d237-0f45-4770-bbad-4a9ebf847ac8@googlegroups.com> (permalink)
Subject Re: Toggle
From Rustom Mody <rustompmody@gmail.com>

Show all headers | View raw


On Friday, October 10, 2014 12:48:20 PM UTC+5:30, Steven D'Aprano wrote:
> 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.

Yeah... in an ideal world politics and science/technology would be separable
if not completely separate. I dont see such a world (round me at least).

See (particularly section 2):
http://blog.jot.fm/2010/08/26/ten-things-i-hate-about-object-oriented-programming/comment-page-2/

> > 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.

> 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.


I think Ive seen a number of confusions on this list from the fact 
that None quietly disappears at REPL top level and no where else.
Yeah this is no str vs repr but print statement/expression vs REPL-print.

> 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". 

Count me as noob then!
http://stackoverflow.com/questions/1436703/difference-between-str-and-repr-in-python
are some explanations:

Alex Martelli:
repr -- should be unambiguous
str -- should be human readable

Ned Batchelder:
repr for developers
str for customers

More telling comments from Alex (same SO post)
1. Both have mostly useless default implementations
2. if you override __repr__, that's ALSO used for __str__, but not vice versa
3. despite the words on the subject found in typical docs, hardly
   anybody bothers making the __repr__ of objects be a string that
   eval may use to build an equal object (it's just too hard, AND not
   knowing how the relevant module was actually imported makes it
   actually flat out impossible).

If you dont find all this confusing, I am reminded of Schrödinger (or
one of his ilk):

If you dont find Quantum physics confusing you've not begun to understand it

For myself: Yeah I understand the philosophy (vaguely)
Exact detailed differences -- I never remember.
In particular when which is called.
Also which defaults to the other.

In any case when teaching beginners, I dont want to have anything to
do with repr. Just as a teacher of school arithmetic does not
generalize arithmetic to Rings and Fields

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Toggle Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-08 20:11 -0400
  Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-09 12:29 +1100
    [OT] spelling colour / color was Re: Toggle mm0fmf <none@mailinator.com> - 2014-10-09 18:43 +0100
      Re: [OT] spelling colour / color was Re: Toggle duncan smith <buzzard@invalid.invalid> - 2014-10-09 19:24 +0100
        Re: [OT] spelling colour / color was Re: Toggle Tim Delaney <timothy.c.delaney@gmail.com> - 2014-10-10 06:53 +1100
          Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-09 23:48 +0300
            Re: [OT] spelling colour / color was Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-10 17:31 +0000
              Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-10 22:01 +0300
                Re: [OT] spelling colour / color was Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-10 20:05 +0000
                Re: [OT] spelling colour / color was Re: Toggle Christian Gollwitzer <auriocus@gmx.de> - 2014-10-11 11:37 +0200
                Re: [OT] spelling colour / color was Re: Toggle mm0fmf <none@mailinator.com> - 2014-10-11 12:45 +0100
                Re: [OT] spelling colour / color was Re: Toggle duncan smith <buzzard@invalid.invalid> - 2014-10-11 16:26 +0100
                Re: [OT] spelling colour / color was Re: Toggle Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-11 15:20 -0400
                Re: [OT] spelling colour / color was Re: Toggle William Ray Wing <wrw@mac.com> - 2014-10-11 15:55 -0400
                Re: [OT] spelling colour / color was Re: Toggle duncan smith <buzzard@invalid.invalid> - 2014-10-12 00:40 +0100
                Re: [OT] spelling colour / color was Re: Toggle giacomo boffi <pecore@pascolo.net> - 2014-10-18 09:06 +0200
                Re: [OT] spelling colour / color was Re: Toggle Simon Ward <simon+python@bleah.co.uk> - 2014-10-11 15:45 +0100
        Re: [OT] spelling colour / color was Re: Toggle "Neil D. Cerutti" <neilc@norwich.edu> - 2014-10-10 10:46 -0400
        Re: [OT] spelling colour / color was Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-10 18:45 +0100
      Re: [OT] spelling colour / color was Re: Toggle Terry Reedy <tjreedy@udel.edu> - 2014-10-09 18:53 -0400
        Re: [OT] spelling colour / color was Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 18:11 +1100
          Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-10 13:08 +0300
            Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 21:40 +1100
              Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-10 13:51 +0300
                Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 22:50 +1100
                Re: [OT] spelling colour / color was Re: Toggle Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-10 20:19 -0400
                Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-11 13:33 +0300
                Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-11 22:03 +1100
      Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 10:21 +1100
      Re: [OT] spelling colour / color was Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 17:52 +1100
        Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 18:04 +1100
      Re: [OT] spelling colour / color was Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-10 18:38 +0100
  Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-09 02:25 +0100
  Re:Toggle Dave Angel <davea@davea.name> - 2014-10-08 21:24 -0400
  Re: Toggle Ben Finney <ben+python@benfinney.id.au> - 2014-10-09 12:42 +1100
    Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-08 19:34 -0700
      Re: Toggle Steven D'Aprano <steve@pearwood.info> - 2014-10-09 04:56 +0000
        Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-08 22:39 -0700
          Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-09 16:55 +1100
          Re: Toggle Peter Otten <__peter__@web.de> - 2014-10-09 09:51 +0200
            Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-09 05:42 -0700
              Re: Toggle Terry Reedy <tjreedy@udel.edu> - 2014-10-09 16:57 -0400
          Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 18:18 +1100
            Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-10 07:24 -0700
              Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-10 07:28 -0700
                Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-11 01:36 +1100
      Re: Toggle Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-09 10:07 -0600
        Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-09 09:33 -0700
          Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 18:15 +1100
  Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-09 04:02 +0100
  Re: Toggle random832@fastmail.us - 2014-10-08 23:54 -0400
  Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-09 14:57 +1100
  Re: Toggle Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-09 17:57 +1300
    Re: Toggle Travis Griggs <travisgriggs@gmail.com> - 2014-10-08 22:38 -0700
    Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-09 15:23 +0000
      Re: Toggle Tony the Tiger <tony@tiger.invalid> - 2014-10-12 18:38 +0000
        Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-13 05:43 +1100
          Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-13 08:09 +0000
  Re: Toggle Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-10-10 13:44 +0200

csiph-web