[Tutor] slow html generation code

Kent Johnson kent37 at tds.net
Thu Mar 3 05:48:54 CET 2005

Danny Yoo wrote:
> It also makes it easier to see a possible bug in the code: the last few
> lines in the 'for' loop look suspicious:
> ######
>         txt = textile(tmp) + '</body></html>'
>         t = Template(txt)
>         s = t.safe_substitute(title='Web-siter: %s' % i[:-5])
>         output = open(page, 'w')
>         output.write('')
>         output.write(s)
> ######
> It does look strange that the file is being open and rewritten over and
> over, for each line in the file.  Are you sure you want to put that in the
> body of the loop?

You are also passing the text through textile / Template / safe_substitute repeatedly. You probably 
want to accumulate all the text, process it once and write it to the file.


More information about the Tutor mailing list