[Tutor] Extracting comments from a file

Lao Mao laomao1975 at googlemail.com
Mon Feb 22 07:06:40 CET 2010


I have an html file, with xml style comments in:

Some comments here

I'd like to extract only the comments.  My sense of smell suggests that
there's probably a library (maybe an xml library) that does this already.
Otherwise, my current alogorithm looks a bit like this:

* Iterate over file
* If current line contains <!---
  - Toggle 'is_comment' to yes
* If is_comment is yes, print the line
* If current line contains -->
  - Toggle 'is_comment' to no

This feels crude, but is it effective, or ok?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100222/45d6d27f/attachment.html>

More information about the Tutor mailing list