[Tutor] Server Error
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Sun Aug 22 08:41:50 CEST 2004
> Actually, the server error shown in my previous mail includes import
> cgitb; cgitb.enable(), thats why I don't understand. Sorry that I didn't
> make myself clear. But still thanks to you.
Ok, I took a look at the problem. There's an issue around line 90 of your
program:
###
if email != None:
Output = Output + "<A HREF="mailto:s4046441 at student.uq.edu.au" + email
+ "">" + name + "</A>.<P>"
###
The class of error here is pure syntax: Python first does a quick pass
through a source file, before execution, to do a "bytecode compile", and
if there are problems at this stage, the system will raise an error, even
before executing a single line in the program. That's why we're not
seeing cgitb output.
The problem is that Python has no idea that the quotes that you're using
here:
if email != None:
Output = Output + "<A HR...
^^^
are any different than the quotes that you're using here:
if email != None:
Output = Output + "<A HREF="mailt...
^^^
Do you see this issue? If you want to embed a literal double-quote
character in a string literal, you'll need to give advanced warning to
Python. Sorta like this:
###
>>> message = "he said: \"like this\""
>>> print message
he said: "like this"
###
The backslash character in front is the start of an "escape" sequence to
tell Python to treat the next character as special: we use it so that
Python knows that more string is coming up.
If a single statement spans multiple lines, you may also need to hint at
Python to expect more. One way to do this is with parentheses:
###
>>> message = ("he said: " +
... "\"like this\"")
>>> message
'he said: "like this"'
###
If you leave the parens out, Python will think the statement is a run-on
statement, and give an error message since it looks bad:
###
>>> message = "he said: " +
File "<stdin>", line 1
message = "he said: " +
^
SyntaxError: invalid syntax
###
Good luck to you!
More information about the Tutor
mailing list