用PYTHON输入输出字符串
2013-11-22 20:17
399 查看
这段好懂的,可以互动。
import sys import re class BadEmployeeFormat(Exception): """Badly formatted employee name""" def get_employee(): """ Retrieve user imformation. This method simply prompts the user for an empoyee's name and his current job title. """ employee = input('Empoyee Name:') role = input("Empoyee's Role:") if not re.match(r'^.+\s.+',employee): raise BadEmployeeFormat('Full Name Requested' 'for records database.') return {'name':employee, 'role':role} if __name__ == '__main__': employees = [] print ('Enter you employee, EOF to Exit...') while True: try: employees.append(get_employee()) except EOFError: print () print ("Empoyee Dump") for number, employee in enumerate(employees): print ('Emp #%d: %s, %s' % (number+1, employee['name'], employee['role'])) print ('Copyright Sign 2010, SuperCompany, Inc.') sys.exit(0) except BadEmployeeFormat as e: print (sys.stderr, 'Error: '+str(e))
相关文章推荐
- python进阶3--文件系统
- [转]python操作MySQL数据库
- 全面解读python web 程序的9种部署方式
- python 如何计算时间差
- 在python中实现数据生成饼图,并且饼图要显示在HTML页面中
- Python源码分析
- [转]浅谈Python web框架
- SimpleClass:Python之面向对象编程
- Python数据库连接池实例——PooledDB
- 输出文件中不包含指定的多个排除词的行内容(双重遍历) 分类: python 小练习 2013-11-22 15:20 605人阅读 评论(0) 收藏
- python字符串连接的N种方式
- Python特殊语法:filter、map、reduce、lambda
- 1.2、安装Django-1.5.1及所需要的Python2.74环境
- Python 模块之 ConfigParser: 用 Python 解析配置文件
- 设置ie代理
- 删除指定路径根目录所有文件-python
- word文档转换为txt-python
- eml邮件格式转换为html-python
- Python中的异常
- python 多进程之管道实例(模板)