[Tutor] Doctype declaration

Kent Johnson kent37 at tds.net
Thu Jul 7 03:37:14 CEST 2005

gordnjen wrote:
> So, now I need to know how to insert a doctype declaration into my 
> python script so that a) the python script runs properly and b)the page 
> validates as valid XHTML.
> Here is my code below. It runs fine as a python script, but won't validate:
> import time
> print "Content-type: text/html"
> print

print '<?xml version="1.0" encoding="UTF-8"?>'
print '''<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'

> print "<head>"
> print "<title>Current Time</title>"
> print "</head><body>"
> print "<h1><b>Current Time</b></h1>"
> print "<p>The current time is"
> print "<strong>", time.asctime(), "</strong></p>"
> print "</body></html>"

By the way, triple-quoted strings are very handy for this, you can just say

print '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>Current Time</title>
<h1><b>Current Time</b></h1>
<p>The current time is'''


More information about the Tutor mailing list