Validating Python - need doctype HTML strict

Ben Sizer kylotan at gmail.com
Mon Jul 10 06:44:23 EDT 2006


PapaRandy wrote:

> When I add the doctype, and other necessities to the .py page
>
> (i.e., <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"" xml:lang="en" lang="en">)
>
> I get an invalid script error.

Bear in mind, that this isn't 'a webpage', it's a computer program that
creates a webpage. So you're not 'adding a doctype', you're 'adding
some code to output a doctype', and similarly it's not Python you're
validating, it's the output it creates that you validate. These are
important distinctions.

Anyway, what is the exact line of code you use to 'add the doctype'?
And what is this 'invalid script error'? It's hard to debug your code
when we have to guess what it is! However, because I'm in a good mood,
I'll have a go.

You probably need to escape the double quotes in the doctype because
they unintentionally correspond with the double quotes in your print
statement. The print statement uses double quotes to delimit the
output, and the doctype uses them to delimit the type. Unfortunately
the print statement probably interprets the start of the doctype's type
field as the end of the print statement. Add a backslash before each
double quote within your doctype and see how that goes. Alternatively
you could possibly use single quotes in it instead.

-- 
Ben Sizer




More information about the Python-list mailing list