[Tutor] Syntax Question
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Wed Feb 8 21:41:10 CET 2006
On Wed, 8 Feb 2006, Rich Shepard wrote:
> I'm trying to understand how to write SQL statements using pysqlite.
> The problem is that if I use newlines to format the SQL statements as I
> would with straight SQLite or PostgreSQL, python complains because it
> sees the newline before the end of the quoted string.
Hi Rich,
Odd. Can you show us that complaint? Show us the error string. There
are several possibilities here, but I hate guessing. *grin* Show us the
exact error message you're getting, and that'll hint at what's really
going on.
Normal string literals can't span lines, but triple-quoted string literals
can:
######
>>> "hello world
File "<stdin>", line 1
"hello world
^
SyntaxError: EOL while scanning single-quoted string
>>> """hello world
... this is a test.
... """
'hello world\nthis is a test.\n'
######
The idea is that it's all to easy to leave off the terminating quote on
single quoted strings, so the SyntaxError tries to be good about giving an
early warning. But if we do want to make a string literal that spans
across lines, we can deliberately do so by using triple-quoted strings.
More information about the Tutor
mailing list