mirror of
https://github.com/python/cpython.git
synced 2024-11-28 04:15:11 +08:00
Tiny utility prints the latest set of reserved words.
This commit is contained in:
parent
78b21cf47a
commit
4408ed5dcb
32
Doc/ref/reswords.py
Normal file
32
Doc/ref/reswords.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""Spit out the Python reserved words table."""
|
||||
|
||||
import string
|
||||
|
||||
raw_words = """
|
||||
and del for is raise
|
||||
assert elif from lambda return
|
||||
break else global not try
|
||||
class except if or while
|
||||
continue exec import pass
|
||||
def finally in print
|
||||
"""
|
||||
|
||||
ncols = 5
|
||||
|
||||
def main():
|
||||
words = string.split(raw_words)
|
||||
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()
|
Loading…
Reference in New Issue
Block a user