[Tutor] a strategy for learning
Sat, 3 Jun 2000 16:27:05 +0200
On Sat, Jun 03, 2000 at 09:05:42AM -0500, firstname.lastname@example.org wrote:
> I have a task for python, but I don't know python yet. Seems like
> this may be a good way to learn. can someone give me a list of steps
> to take?
> I have a directory full of html files, named by number (1.html,
> 2.html, etc). I want to create a page of links to each of them
> based on the text surrounded by the second set of <h2> tags in each
> This sound reasonable?
It's reasonable, but it depends a bit on how "nice" the html files are.
As long as they're simple enough to do a simple text search for "<h2>", it's
not so hard. If there's a chance of stuff like '<sometag value="<h2>">' or
'<!-- <h2>' you will have to use a real HTML parser, and that will take
longer to learn.
Your first step would be to find a tutorial and find out how Python uses
strings, lists, and files. Play around with them a bit in the interpreter (I
don't know if you can already program a bit, but this shouldn't be hard).
Then the program should just
- Get the list of files (os.listdir)
- For each of the files,
- Read it in
- Find the second <h2>
- Find the first </h2> after that
- Append the text in between to a list
- Write a HTML file based on the list
None of these steps should be hard once you know how to use files,
strings and lists.
Remco Gerlich, email@example.com