一、问题
Python标识符必须以字母或下划线开头,后面跟字母、下划线或者数字,且标识符不能为关键字,如何有效的检查?
二、解决
1、方法一
(1)python脚本
新建idcheck.py,输入代码,然后执行pythonidcheck.py。
#!/usr/bin/env python
'''
$Id$
idcheck.py -- checks identifiers for validity
This application is limited in that it currently only supports
checking identifiers with length > 1 (does not process identifiers
of length greater than 1. This application also does not recognize
do keywords.
Exercise:
6-2) update this script to process identifiers of length 1
as well as recognizing keywords as invalid identifiers
(for use by the programmer; they are valid Python
identifiers otherwise).
'''
import string # string utility module
# create alphabet and number sets
alphas = s