473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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?
Jun 27 '08 #1
4 2199
* wx********@gmail.com <wx********@gmail.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)

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

Jun 27 '08 #2
On May 11, 6:56 am, wxPytho...@gmail.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:
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:
>>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
Jun 27 '08 #3
wx********@gmail.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.
Jun 27 '08 #4
Dennis Lee Bieber <wl*****@ix.netcom.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.

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 431 open ( +3) / 3425 closed ( +8) / 3856 total (+11) Bugs : 916 open (-23) / 6273 closed (+44) / 7189 total (+21) RFE : 244 open...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
40
by: brad | last post by:
Will len(a_string) become a_string.len()? I was just reading http://docs.python.org/dev/3.0/whatsnew/3.0.html One of the criticisms of Python compared to other OO languages is that it isn't OO...
19
by: Terry Reedy | last post by:
"Luis Zarrabeitia" <kyrie@uh.cuwrote in message news:200805081914.06459.kyrie@uh.cu... | Btw, there seems to be a math problem in python with exponentiation... | >>0**0 | 1 | That 0^0 should be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.