[EMAIL PROTECTED] wrote:
> The HTML comes from a bunch of files which are saved in my computer.They
> were generated by a php script and I want to extract certain fields for
> insertion in to a MySQL db.
> I`m trying to get the hang of correctly opening the files first :)
> There are about a thousand of them so I have to use a loop in the script
> since the files are named article1.html,article2.html,etc.
> Thanks for the help!

Try something like this:

def process(data):
   # this is a function you define to process the data from one file

maxFileIndex = ... # whatever the max count is
for i in range(1, maxFileIndex+1):  # i will take on each value
                                     # from 1 to maxFileIndex
   name = 'article%s.html' % i  # make a file name
   f = open(name)  # open the file and read its contents
   data = f.read()
   f.close()
   process(data)

Kent

PS Please reply to the list

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to