File: reswords.py

package info (click to toggle)
python2.5-doc 2.5.2-2
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 7,828 kB
  • ctags: 2,723
  • sloc: python: 5,817; perl: 3,674; sh: 1,643; makefile: 1,352; lisp: 854; xml: 836; ansic: 798; 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()