[Tutor] slow html generation code

Luis N tegmine at gmail.com
Thu Mar 3 00:59:58 CET 2005

This code seems a little slow, is there anything in particular that
jumps out as being not quite right.

The idea is that a file is opened that contains path names to other
files, that are appended and outputed into a directory of choice.

I plan to move this off the filesystem into a database when the
concept is worked out, maybe that will help.


import sys
import os
from string import Template
from textile import textile

def main(files):
    if len(files) < 1:
        print 'Feed me with XHTML, String Templates, and Textile'
        path = os.path.expanduser('~/')
        publish = os.path.join(path, 'publish')
        pages = os.path.join(publish, 'pages')
        write = os.path.join(path, 'public_html/write')
            for i in files:
                page = os.path.join(write, i)
                f = open(os.path.join(pages, i), 'r')
                tmp = ""
                for line in f.readlines():
                    line = line.rstrip()
                    structure = open(os.path.join(publish, line))
                    clean = structure.read()
                    tmp = tmp + clean.rstrip()
                    txt = textile(tmp) + '</body></html>'
                    t = Template(txt)
                    s = t.safe_substitute(title='Web-siter: %s' % i[:-5])
                    output = open(page, 'w')

if __name__ == '__main__':

More information about the Tutor mailing list