#!/usr/bin/env python import cgitb cgitb.enable() import glob png = glob.glob('mini/*.png') jpg = glob.glob('mini/*.jpg') images = list(filename[5:-4] for filename in (png + jpg)) p = len(images) / 5 first = images[:p] second = images[p:p*2] third = images[p*2:p*3] fourth = images[p*3:p*4] fifth = images[p*4:] print 'Content-Type: text/html; charset=utf-8' print print """\
' for image in part: print '' % (image, image, image) print ' | ' print """\