.NODE

The keyword Module

The keyword module (see Example 13-18) contains a list of the keywords used in the current version of Python. It also provides a dictionary with the keywords as keys, and a predicate function that can be used to check if a given word is a Python keyword.

Example 13-18. Using the keyword Module
File: keyword-example-1.py

import keyword

name = raw_input("Enter module name: ")

if keyword.iskeyword(name):
 print name, "is a reserved word."
 print "heres a complete list of reserved words:"
 print keyword.kwlist

Enter module name: assert
assert is a reserved word.
heres a complete list of reserved words:
[and, assert, reak, class, continue, def, del,
elif, else, except, exec, finally, for, from,
global, if, import, in, is, lambda, 
ot, or,
pass, print, 
aise, 
eturn, 	ry, while]

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols

Internationalization

Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules

show all menu





Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net