From: Circa
Subject: Validating Python doctype as HTML strict
Date: 
Message-ID: <1152486504.048593.22740@h48g2000cwc.googlegroups.com>
Hello,

I am trying to validate the following .py webpage as HTML (through
W3C).

I put:

-----------------------------------------------------------------------------

print "Content-type: text/html; charset=utf-8"

import time

print

print """<html><head>

<title>Current Time</title>

</head> <body>

<h1>Current Time</h1>"""

print "<p>Right now, it is "

print "<strong>", time.asctime(), "</strong></p>"

print "</body></html>"

---------------------------------------------------

However, the .py page should also be valid (X)HTML - it needs a
doctype...

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.

Can anyone help me to get the XHTML doctype to validate and execute on
Python web page?


Thank you!

From: Nathan Baum
Subject: Re: Validating Python doctype as HTML strict
Date: 
Message-ID: <1152499398.947750.122430@35g2000cwc.googlegroups.com>
Doctor, doctor, I need glasses.

You certainly do, sir, this is a fish and chip shop!
From: Stefan Scholl
Subject: Re: Validating Python doctype as HTML strict
Date: 
Message-ID: <0T39vflqIg81Nv8%stesch@parsec.no-spoon.de>
I will not buy this record. It is scratched.
From: Circa
Subject: Re: Validating Python doctype as HTML strict
Date: 
Message-ID: <1152648091.053851.298320@m79g2000cwm.googlegroups.com>
Thanks for your helpful comments.

The answer to my question was to enclose the string in """ triple
quotes """" and place doctype stuff in the head, before the body:

------------------------------------

import time

#print HTTP/HTML header stuff
print """Content-type: text/html; charset=utf-8\n\n

<!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">

<head>

<title>Current Time</title>

</head> <body>
"""

print

#print HTML body using Python-HTML hybrid script
print "<h1>Current Time</h1>"

print "<p>Right now, it is "

print "<strong>", time.asctime(), "</strong></p>"

print """<p>
    <a href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
  </p>
"""

print "</body></html>"

--------------------

Nice that you guys knew everything straight off.
From: Nathan Baum
Subject: Re: Validating Python doctype as HTML strict
Date: 
Message-ID: <1152657095.480381.137380@75g2000cwc.googlegroups.com>
Circa wrote:
> Thanks for your helpful comments.

This is comp.lang.lisp. What inspired you to think that a group about
the COMPuter LANGuage LISP was the ideal forum for questions about
Python? What would have been wrong with comp.lang.python?

Even if this was the right group -- even if you were using Lisp rather
than Python -- your question still sucks. You're asking for help
diagnosing an error in your code, but don't post either the code which
actually causes the error, or the error message itself. We'd have a
hard time figuring that one out.

"This code works, but when I make unspecified modifications, it fails
in an unspecified way. Please tell me what's wrong."

Furthermore, the actual error message you would have received is
"SyntaxError: EOL while scanning single-quoted string," which leaves no
doubt in *my* mind as to what the cause of the problem is.
From: Circa
Subject: Re: Validating Python doctype as HTML strict
Date: 
Message-ID: <1152739325.268515.242000@i42g2000cwa.googlegroups.com>
Right, I did erroneously enter this group when logging into Google
Groups for the second time in my long life. As soon as I realised my
mistake I did log into comp.lang.python, and post a similar message
there - the sucky question I had. (If you go there, you can see a nice
person there corrected me as to what I need to include in my question,
and nicely took a stab at the problem anyway - with minimal sarcasm.
http://groups.google.com/group/comp.lang.python/browse_thread/thread/2337229e874276f4)

I didn't get a syntax error message at first since I was trying to
validate python code that had no errors (using w3c validator) - all I
got was a failed validation (http://www.w3.org/) because the doctype
was not included in the header. (I thought that answering the question
of how to add a doctype using Python would be easy.)

Anyway, in order to make it xtmhl strict, l tried to add the doctype,
at which point it complained with the following, when I went to the
webpage:

"Script Error

There was an error with your script and it didn't exit properly.

This was its output:

  File "/home/location/public_html/testnow.py", line 3
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    ^
SyntaxError: invalid syntax

(Error code: 1)"

This message was generated by CGIHelper."


I understand by your comment that I should have been using the Python
command line?  To be honest - any error message means nothing to me
other than it isn't working!

I thought the problem was a simple one since I'm soooo new with this
and that there would be an easy answer to the question of how to add a
doctype to a python program. Boy, was I wrong! I guess something that
seems like a simple question isn't always the case, so it is important
to include the error message when asking...

Someone *please* flog the stupid, stupid girl for asking stupid
questions, stupidly...

:)

Nathan Baum wrote:
> Circa wrote:
> > Thanks for your helpful comments.
>
> This is comp.lang.lisp. What inspired you to think that a group about
> the COMPuter LANGuage LISP was the ideal forum for questions about
> Python? What would have been wrong with comp.lang.python?
>
> Even if this was the right group -- even if you were using Lisp rather
> than Python -- your question still sucks. You're asking for help
> diagnosing an error in your code, but don't post either the code which
> actually causes the error, or the error message itself. We'd have a
> hard time figuring that one out.
>
> "This code works, but when I make unspecified modifications, it fails
> in an unspecified way. Please tell me what's wrong."
>
> Furthermore, the actual error message you would have received is
> "SyntaxError: EOL while scanning single-quoted string," which leaves no
> doubt in *my* mind as to what the cause of the problem is.
From: Stefan Scholl
Subject: Re: Validating Python doctype as HTML strict
Date: 
Message-ID: <0T3a3ot8I3lhNv8%stesch@parsec.no-spoon.de>
Circa <·········@hotmail.com> wrote:
> Thanks for your helpful comments.

Well, maybe Google isn't very useful for Usenet.

I remember a lot of postings about CD-ROMs in a communication
software newsgroup. All from Google users, going on for many
years.

And now you, who wants some answers to Python (the language)
answers in a Lisp newsgroup.


OK, there are some occasional Windows users who ask Linux
users, because they think Linux users know more ...