file handling

tjernstrom at my-deja.com tjernstrom at my-deja.com
Thu Aug 10 05:40:06 EDT 2000


I'm new to Python and have trouble finding an answer to a simple
question.

I have written a small script that process html-files. All I need to do
is find a way to send all html files in a directory to this file while
ignoring the rest of the files in this directory (and do the same for
all the subdirectories).
Here's my short script:

import re
def ProcessFile(file, spath, tpath):
    sf = open(spath+file, 'r')
    tf = open(tpath+file, 'w')
    tagstart = re.compile('<FONT SIZE="-2">')
    tagend = re.compile('</FONT>')
    anchorstart = re.compile('¤¤¤')
    anchorend = re.compile('¤#¤')
    line = ' '
    while line != '':
	line = sf.readline()
	line = tagstart.sub('<CODE>', line)
	line = tagend.sub('</CODE>', line)
	line = anchorstart.sub('<a name="', line)
	line = anchorend.sub('"></a>', line)
	tf.write(line)
    sf.close()
    tf.close()

I'd really apreciate help or some tips on where in the documentation to
look for answers.


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list