Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old June 27th, 2008, 05:24 PM
wxPythoner@gmail.com
Guest
 
Posts: n/a
Default Python doesn't recognize quote types

There's a thing that bugs me in Python. Look at this...
Quote:
Quote:
Quote:
>>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?
  #2  
Old June 27th, 2008, 05:24 PM
Nicolas Dandrimont
Guest
 
Posts: n/a
Default Re: Python doesn't recognize quote types

* wxPythoner@gmail.com <wxPythoner@gmail.com[2008-05-10 13:56:39 -0700]:
Quote:
There's a thing that bugs me in Python. Look at this...
Quote:
Quote:
>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)

iD8DBQFIJhBbacIxuZqlam0RAkiSAJ45YCIhnsSrOlK4ZEijkY Y3kwz4xQCfazat
Y7eHbwTFb1coeCJ6MBSJw64=
=Oz3f
-----END PGP SIGNATURE-----

  #3  
Old June 27th, 2008, 05:24 PM
John Machin
Guest
 
Posts: n/a
Default Re: Python doesn't recognize quote types

On May 11, 6:56 am, wxPytho...@gmail.com wrote:
Quote:
There's a thing that bugs me in Python. Look at this...
>
Quote:
Quote:
>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:
http://docs.python.org/ref/strings.html

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

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:
Quote:
Quote:
Quote:
>>print "She said \"Hello!\""
She said "Hello!"
Quote:
Quote:
Quote:
>>print 'His surname is "O\'Brien"'
His surname is "O'Brien"
Quote:
Quote:
Quote:
>>>
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


  #4  
Old June 27th, 2008, 05:24 PM
Duncan Booth
Guest
 
Posts: n/a
Default Re: Python doesn't recognize quote types

wxPythoner@gmail.com wrote:
Quote:
There's a thing that bugs me in Python. Look at this...
>
Quote:
Quote:
>>>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.
  #5  
Old June 27th, 2008, 05:24 PM
Duncan Booth
Guest
 
Posts: n/a
Default Re: Python doesn't recognize quote types

Dennis Lee Bieber <wlfraed@ix.netcom.comwrote:
Quote:
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.

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles