用PYTHON输入输出字符串
这段好懂的,可以互动。
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输入输出字符串的更多相关文章
- Python 输入输出 数据类型 变量
python输入输出 数据类型 变量 输入输出 print()在Python3中是函数 >>>print('hello world') #print注意print前面不要有任何空格 ...
- Python格式化字符串~转
Python格式化字符串 在编写程序的过程中,经常需要进行格式化输出,每次用每次查.干脆就在这里整理一下,以便索引. 格式化操作符(%) "%"是Python风格的字符串格式化操作 ...
- python学习--字符串
python的字符串类型为str 定义字符串可以用 ‘abc' , "abc", '''abc''' 查看str的帮助 在python提示符里 help(str) python基于 ...
- Python格式化字符串和转义字符
地址:http://blog.chinaunix.net/uid-20794157-id-3038417.html Python格式化字符串的替代符以及含义 符 号 说 明 ...
- [转载] python 计算字符串长度
本文转载自: http://www.sharejs.com/codes/python/4843 python 计算字符串长度,一个中文算两个字符,先转换成utf8,然后通过计算utf8的长度和len函 ...
- Python基础-字符串格式化_百分号方式_format方式
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- python判断字符串
python判断字符串 s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小 ...
- Python格式化字符串
在编写程序的过程中,经常需要进行格式化输出,每次用每次查.干脆就在这里整理一下,以便索引. 格式化操作符(%) "%"是Python风格的字符串格式化操作符,非常类似C语言里的pr ...
- python(七)字符串格式化、生成器与迭代器
字符串格式化 Python的字符串格式化有两种方式:百分号方式.format方式 1.百分号的方式 %[(name)][flags][width].[precision]typecode (name) ...
随机推荐
- careercup-栈与队列 3.5
3.5 实现一个MyQueue类,该类用两个栈来实现一个队列. 解答 队列是先进先出的数据结构(FIFO),栈是先进后出的数据结构(FILO), 用两个栈来实现队列的最简单方式是:进入队列则往第一个栈 ...
- C# DataTable怎么合计字段
DataTable dt = new DataTable(); var age=dt.Compute("avg(age)",""); var height =d ...
- find grep使用
-------------------------------------find---grep---------------------------------------- 在当前目录下所有文件中 ...
- Windows7服务无法启动的解决
这周六,我接到了一个很诡异的案例,表现为任务栏右下角网络连接图标始终为一个红叉,已排除网卡硬件.链路和网卡驱动的问题.主板都新换了一块,可是问题依旧,这无疑将问题的根源指向了操作系统.本想通过网络疑难 ...
- 11.12 noip模拟试题
题目名称 加密 冒泡排序图 重建可执行文件名 encrypt bubble rebuild输入文件名 encrypt.in bubble.in rebuild.in输出文件名 encrypt.in b ...
- 删除mysql重复记录的办法
网上有很多的办法,但是大多数都是通过临时表的办法,其实你是可以用一句简单的sql就可以做到: alter ignore table SOMETABLE add primary key(fields n ...
- 整理收藏一份PHP高级工程师的笔试…
注:本文转自 http://www.icultivator.com/p/5535.html 注:本文转自 http://www.yiichina.com/tutorial/57 整理了一份PHP高级工 ...
- (转)javascript中的this
JavaScript中的this总是让人迷惑,应该是js众所周知的坑之一. 个人也觉得js中的this不是一个好的设计,由于this晚绑定的特性,它可以是全局对象,当前对象,或者…有人甚至因为坑大而不 ...
- 在.Net中进行跨线程的控件操作(上篇:Control.Invoke)
本文的重点在于介绍如何在多线程编程中,从非UI线程上访问界面中的控件.有过多线程编程经验的人都知道,当我们在非UI线程上试图给一个界面中的控件赋值的时候,比如说label的Text属性,系统会抛出一个 ...
- count(*),count(1)和count(主键) 区别
看如下数据: SQL> select count(*) from ysgl_compile_reqsub; COUNT(*) ---------- 已用时间: : : 07.51 SQL) fr ...