Re: Linux.com: Python 3 makes a big break

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Paul Calderone

    Re: Linux.com: Python 3 makes a big break

    On Sat, 18 Oct 2008 15:30:23 -0400, Terry Reedy <tjreedy@udel.e duwrote:
    >http://www.linux.com/feature/150399
    >Interesting article with one minor incompleteness.
    >"For instance, the print statement got turned into a print function; you
    >must now put parentheses around what you want to print to the screen. The
    >change allows developers to work with print in a more flexible and uniform
    >way. If someone needs to replace the print function with some other action,
    >it can be done with a universal search and replace, rather than rewriting
    >each print statement by hand."
    >
    >Even easier, print as a function can be replaced simply by defining a new
    >version with the same name. No search/replace is needed. And reversion to
    >the built-in only requires commenting out the replacement.
    Perhaps it also omitted the fact that nothing prevents you from defining a
    function to write things to stdout (or elsewhere) in Python 2.5, making the
    Python 3.x change largely a non-feature. ;)

    Jean-Paul
  • Kay Schluehr

    #2
    Re: Linux.com: Python 3 makes a big break

    On 18 Okt., 22:01, Jean-Paul Calderone <exar...@divmod .comwrote:
    Perhaps it also omitted the fact that nothing prevents you from defining a
    function to write things to stdout (or elsewhere) in Python 2.5, making the
    Python 3.x change largely a non-feature. ;)
    >
    Jean-Paul
    Even more. If someone had solved the hard problem of finding a less
    cumbersome way of writing sys.stdout.writ e(...) the request for
    multiline lambdas ( multi expression lambdas actually ) could have
    been decreased about 75-80%.

    Comment

    • Lawrence D'Oliveiro

      #3
      Re: Linux.com: Python 3 makes a big break

      In message
      <deb99bf0-c418-4f18-823a-8b9f2e4c5cc0@g6 1g2000hsf.googl egroups.com>, Kay
      Schluehr wrote:
      If someone had solved the hard problem of finding a less
      cumbersome way of writing sys.stdout.writ e(...) ...
      I don't see what the big deal is. I regularly write things like

      sys.stdout.writ e \
      (
      "<INPUT TYPE=\"RADIO\" NAME=\"%(name)s \""
      " ID=\"%(name)s[%(value)s]\" VALUE=\"%(value )s\"%(checked)s >"
      "<LABEL FOR=\"%(name)s[%(value)s]\">%(title)s </LABEL>\n"
      # using LABEL lets user click on text to select button
      %
      {
      "name" : EscapeHTML(Name ),
      "value" : EscapeHTML(Valu e),
      "title" : Title,
      "checked" : ("", " CHECKED")[Checked],
      }
      )

      Comment

      • Steven D'Aprano

        #4
        Re: Linux.com: Python 3 makes a big break

        On Sat, 18 Oct 2008 21:34:13 -0700, Kay Schluehr wrote:
        On 18 Okt., 22:01, Jean-Paul Calderone <exar...@divmod .comwrote:
        >
        >Perhaps it also omitted the fact that nothing prevents you from
        >defining a function to write things to stdout (or elsewhere) in Python
        >2.5, making the Python 3.x change largely a non-feature. ;)
        >>
        >Jean-Paul
        >
        Even more. If someone had solved the hard problem of finding a less
        cumbersome way of writing sys.stdout.writ e(...) the request for
        multiline lambdas ( multi expression lambdas actually ) could have been
        decreased about 75-80%.

        Er, am I missing something? How about this?

        import sys
        pr = sys.stdout.writ e

        pr('Is this less cumbersome enough for you?')

        But of course, that doesn't really help you avoid multi-expression
        lambdas, unless you want to write obfuscated code:

        def foo(x):
        y = x+1
        print y
        return y

        is roughly, but inefficiently, equivalent to:

        lambda x: sys.stdout.writ e(x+1) or x+1

        But that's cumbersome and obfuscated, and not scalable at all.



        --
        Steven

        Comment

        • Aahz

          #5
          Re: Linux.com: Python 3 makes a big break

          In article <gdeof0$d3b$3@l ust.ihug.co.nz> ,
          Lawrence D'Oliveiro <ldo@geek-central.gen.new _zealandwrote:
          >In message
          ><deb99bf0-c418-4f18-823a-8b9f2e4c5cc0@g6 1g2000hsf.googl egroups.com>, Kay
          >Schluehr wrote:
          >>
          >If someone had solved the hard problem of finding a less
          >cumbersome way of writing sys.stdout.writ e(...) ...
          >
          >I don't see what the big deal is. I regularly write things like
          >
          sys.stdout.writ e \
          (
          "<INPUT TYPE=\"RADIO\" NAME=\"%(name)s \""
          " ID=\"%(name)s[%(value)s]\" VALUE=\"%(value )s\"%(checked)s >"
          "<LABEL FOR=\"%(name)s[%(value)s]\">%(title)s </LABEL>\n"
          # using LABEL lets user click on text to select button
          %
          {
          "name" : EscapeHTML(Name ),
          "value" : EscapeHTML(Valu e),
          "title" : Title,
          "checked" : ("", " CHECKED")[Checked],
          }
          )
          Why are you using a backslash?
          --
          Aahz (aahz@pythoncra ft.com) <* http://www.pythoncraft.com/

          import antigravity

          Comment

          • D'Arcy J.M. Cain

            #6
            Re: Linux.com: Python 3 makes a big break

            On 19 Oct 2008 07:44:52 -0700
            aahz@pythoncraf t.com (Aahz) wrote:
            sys.stdout.writ e \
            (
            >
            Why are you using a backslash?
            Because he hasn't opened the paren yet. He could have put the open
            paren on the same line as the write obviating the need for the
            backslash but then his open/close parens wouldn't line up. It just a
            matter of style.

            --
            D'Arcy J.M. Cain <darcy@druid.ne t | Democracy is three wolves
            http://www.druid.net/darcy/ | and a sheep voting on
            +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

            Comment

            • Aahz

              #7
              Re: Linux.com: Python 3 makes a big break

              In article <mailman.2664.1 224428124.3487. python-list@python.org >,
              D'Arcy J.M. Cain <darcy@druid.ne twrote:
              >On 19 Oct 2008 07:44:52 -0700
              >aahz@pythoncra ft.com (Aahz) wrote:
              >> sys.stdout.writ e \
              >> (
              >>
              >Why are you using a backslash?
              >
              >Because he hasn't opened the paren yet. He could have put the open
              >paren on the same line as the write obviating the need for the
              >backslash but then his open/close parens wouldn't line up. It just a
              >matter of style.
              Well, no, it's not *just* a matter of style. I'm strongly opposed to
              backslashes because they break when you get whitespace after them. (And
              note carefully that I said "when" and not "if".)
              --
              Aahz (aahz@pythoncra ft.com) <* http://www.pythoncraft.com/

              import antigravity

              Comment

              • Lawrence D'Oliveiro

                #8
                Re: Linux.com: Python 3 makes a big break

                In message <vZGdncBxAJO_4G bVnZ2dnUVZ_qvin Z2d@earthlink.c om>, Dennis Lee
                Bieber wrote:
                There is also the matter that the original material is using " on
                each line to delimit the string, and then \" within the line to escape
                the desired output "s, rather than either using ' for the string and
                bare " for the output characters ...
                I prefer using double-quotes universally. One less decision to make.
                ... or triple quoting the whole block...
                Not a good idea.

                Comment

                • Lawrence D'Oliveiro

                  #9
                  Re: Linux.com: Python 3 makes a big break

                  In message <gdfrf4$odo$1@p anix3.panix.com >, Aahz wrote:
                  I'm strongly opposed to backslashes because they break when you get
                  whitespace after them.
                  1) I've never had that problem.
                  2) Even if I did, it would report a syntax error, it's not going to fail
                  silently and introduce any run-time bugs, is it?

                  Comment

                  Working...