File: reswords.py

package info (click to toggle)
python2.4-doc 2.4.4-2
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k
  • size: 6,860 kB
  • ctags: 2,455
  • sloc: python: 5,194; perl: 3,666; sh: 1,605; makefile: 1,174; xml: 836; lisp: 836; ansic: 718; sed: 2
file content (23 lines) | stat: -rw-r--r-- 515 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Spit out the Python reserved words table."""

import keyword

ncols = 5

def main():
    words = keyword.kwlist[:]
    words.sort()
    colwidth = 1 + max(map(len, words))
    nwords = len(words)
    nrows = (nwords + ncols - 1) / ncols
    for irow in range(nrows):
        for icol in range(ncols):
            i = irow + icol * nrows
            if 0 <= i < nwords:
                word = words[i]
            else:
                word = ""
            print "%-*s" % (colwidth, word),
        print

main()