import os from stat import * print '''
Webware CGI Examples
''' def sizeSorter(a, b): """ Used for sorting when the elements are dictionaries and the attribute to sort by is 'size'. """ return a['size'] - b['size'] # Create a list of dictionaries, where each dictionary stores information about # a particular script. scripts = [] for filename in os.listdir(os.curdir): if len(filename) > 3 and filename[-3:] == '.py': script = {} script['pathname'] = filename script['size'] = os.stat(script['pathname'])[ST_SIZE] script['shortname'] = filename[:-3] scripts.append(script) scripts.sort(sizeSorter) print '| Size | Script | View |
|---|---|---|
| %d | ' % script['size'], print '%s | ' % (script['shortname'], script['shortname']), print 'view | ' % script['shortname'], print '