Python doesn't recognize quote types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wxPythoner@gmail.com

    Python doesn't recognize quote types

    There's a thing that bugs me in Python. Look at this...
    >>print "Testing\"
    SyntaxError: EOL while scanning single-quoted string


    Please focus on the part of the error message that states "while
    scanning single-quoted string". How can Python claim it scanned a
    single-quoted string when I fed it with a double-quoted string? Is
    quote type (single quote and double quote) recognition not implemented
    in Python?
  • Nicolas Dandrimont

    #2
    Re: Python doesn't recognize quote types

    * wxPythoner@gmai l.com <wxPythoner@gma il.com[2008-05-10 13:56:39 -0700]:
    There's a thing that bugs me in Python. Look at this...
    >print "Testing\"
    SyntaxError: EOL while scanning single-quoted string


    Please focus on the part of the error message that states "while
    scanning single-quoted string". How can Python claim it scanned a
    single-quoted string when I fed it with a double-quoted string? Is
    quote type (single quote and double quote) recognition not implemented
    in Python?
    The "single-quoted string" (e.g. 'foo' or "bar") is so named by
    opposition to triple-quoted (e.g. '''foo''' or """bar""") strings.

    Regards,
    --
    Nicolas Dandrimont


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFIJhBbacI xuZqlam0RAkiSAJ 45YCIhnsSrOlK4Z EijkYY3kwz4xQCf azat
    Y7eHbwTFb1coeCJ 6MBSJw64=
    =Oz3f
    -----END PGP SIGNATURE-----

    Comment

    • John Machin

      #3
      Re: Python doesn't recognize quote types

      On May 11, 6:56 am, wxPytho...@gmai l.com wrote:
      There's a thing that bugs me in Python. Look at this...
      >
      >print "Testing\"
      >
      SyntaxError: EOL while scanning single-quoted string
      >
      Please focus on the part of the error message that states "while
      scanning single-quoted string". How can Python claim it scanned a
      single-quoted string when I fed it with a double-quoted string? Is
      quote type (single quote and double quote) recognition not implemented
      in Python?
      Read this:


      Try each of these:
      print 'Testing
      print 'Testing\'
      print 'Testing\'Testi ng
      print 'Testing'
      print 'Testing\''
      print 'Testing\'Testi ng'

      There's a wrinkle that's common to both your questions: \" causes the
      " not to be regarded as (part of) the end marker but to be included as
      a data character. Similarly with '. Examples:
      >>print "She said \"Hello!\""
      She said "Hello!"
      >>print 'His surname is "O\'Brien"'
      His surname is "O'Brien"
      >>>
      In the error message, "quoted" is the past tense of the verb "to
      quote", meaning to wrap a string of characters with a leading string
      and a trailing string to mark the contained string as a lexical item,
      typically a string constant. The message is intended to convey that
      the leading marker has been seen, but an EOL (end of line) was reached
      without seeing the trailing marker.

      A better error message might be something like "String constant not
      terminated at end of line".

      Unfortunately the above-mentioned documentation uses xxxxle-quote as a
      noun to describe characters -- IMHO this is colloquial and confusing;
      it should call ' an apostrophe, not a "single-quote", and all " a
      quote, not a "double-quote". The confusion is compounded by referring
      to '''abc''' and """xyz""" as triple-quoted strings ... so one might
      expect 'abc' and "xyz" to be called "single-quoted strings", and this
      sense is what is being used in the error message.

      HTH,
      John


      Comment

      • Duncan Booth

        #4
        Re: Python doesn't recognize quote types

        wxPythoner@gmai l.com wrote:
        There's a thing that bugs me in Python. Look at this...
        >
        >>>print "Testing\"
        SyntaxError: EOL while scanning single-quoted string
        >
        >
        Please focus on the part of the error message that states "while
        scanning single-quoted string". How can Python claim it scanned a
        single-quoted string when I fed it with a double-quoted string? Is
        quote type (single quote and double quote) recognition not implemented
        in Python?
        >
        Of course it is, but that isn't what is meant here.

        Python supports single-quoted strings which are delimited by either a
        single quote or a double quote mark. It also supports triple-quoted strings
        which are delimited either by three single quotes or three double quotes.

        The overloaded meaning of 'single' is perhaps unfortunate.

        Comment

        • Duncan Booth

          #5
          Re: Python doesn't recognize quote types

          Dennis Lee Bieber <wlfraed@ix.net com.comwrote:
          The sloppy use of "single quote" for the "apostrophe " is unfortunate
          ><G>
          True, but that problem is outside of the Python community's control. Given
          that people do often refer to single quote when they mean apostrophe the
          error message should be written so as to minimise confusion.

          Comment

          Working...