Question regarding HTMLParser module.

Adonis adonisv at
Mon Jul 28 06:05:27 CEST 2003

When parsing my html files, I use handle_pi to capture some embedded python
code, but I have noticed that in the embedded python code if it contains
html, HTMLParser will parse it as well, and thus causes an error when I exec
the code, raises an EOL error. I have a work around for this as I use
different set of characters rather that <tag> use something like (tag) then
revert it back to <tag> via another function, I was wondering if there is a
way to tell HTMLParser to ignore the embedded tags or another alternative?

Any help would be greatly appreciated.
And another note, I am well aware of Zope, Webware, CherryPy, etc... for
py/html embedding options, but I want this to be a learning experience.

HTML processing instruction:
import time
print time.strftime('%b-%d-%Y')
print '<tt>testing!()</tt>')

Traceback (most recent call last):
  File "C:\home\Adonis\python\", line 40, in -toplevel-
  File "C:\Python23\lib\", line 108, in feed
  File "C:\Python23\lib\", line 154, in goahead
    k = self.parse_pi(i)
  File "C:\Python23\lib\", line 232, in parse_pi
    self.handle_pi(rawdata[i+2: j])
  File "C:\home\Adonis\python\", line 33, in handle_pi
  File "<string>", line 4
    print '<tt
SyntaxError: EOL while scanning single-quoted string

More information about the Python-list mailing list