Python 实现简单的命名合法性检查
2015-01-09 09:55
330 查看
#!/usr/bin/env python def identifierChecker(): import string alphas = string.ascii_letters + '_' nums = string.digits alphanums = alphas + nums print 'Welcome to the Identifier Checker v1.0' print 'Testees must be at least 2 chars long.' myInput = raw_input('Identifier to test? ') if len(myInput) > 1: if myInput[0] not in alphas: print '''invalid: first symbol must be alphabetic''' else: for otherChar in myInput [1:]: if otherChar not in alphanums: print '''invalid: remaining symbols must be alphanumeric''' break else: print "Okay as an identifier"
In [8]: identifierChecker() Welcome to the Identifier Checker v1.0 Testees must be at least 2 chars long. Identifier to test? count4rer Okay as an identifier In [9]: identifierChecker() Welcome to the Identifier Checker v1.0 Testees must be at least 2 chars long. Identifier to test? 3d_effects invalid: first symbol must be alphabetic In [11]: identifierChecker() Welcome to the Identifier Checker v1.0 Testees must be at least 2 chars long. Identifier to test? 1 In [12]:
相关文章推荐
- python设置检查点简单实现
- 用 scanf 系列函数实现简单的 email 地址合法性检查功能
- python设置检查点简单实现代码
- python设置检查点简单实现代码
- Python中实现参数类型检查的简单方法
- 检查数据库数据字段命名规范和合法性的脚本
- 简单的实现JAVASCRIPT命名空间
- 最简单的Python singleton模式实现
- 用python实现的简单Server/Client文件传输
- [python]有限状态机(FSM)简单实现
- 通过检查前导页实现的简单的防盗链功能
- 检查数据库数据字段命名规范和合法性的脚本
- 用vbs实现的简单的服务器文件备份办法压缩文件名自动按日期命名
- 检查数据库数据字段命名规范与合法性的脚本
- Pexpect简单的测试——一个 expect的python实现
- [python]有限状态机(FSM)简单实现
- 用于网页判断的智能代理技术的简单实现------------基于python实现(网络爬虫)
- linux下简单的自适应CPU利用率的控制(Python实现)
- python中如何简单的实现decorator模式--由django admin源码所得体会
- 检查数据库字段命名规范与合法性的脚本