这段好懂的,可以互动。

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输入输出字符串的更多相关文章

  1. Python 输入输出 数据类型 变量

    python输入输出 数据类型 变量 输入输出 print()在Python3中是函数 >>>print('hello world') #print注意print前面不要有任何空格 ...

  2. Python格式化字符串~转

    Python格式化字符串 在编写程序的过程中,经常需要进行格式化输出,每次用每次查.干脆就在这里整理一下,以便索引. 格式化操作符(%) "%"是Python风格的字符串格式化操作 ...

  3. python学习--字符串

    python的字符串类型为str 定义字符串可以用 ‘abc' , "abc", '''abc''' 查看str的帮助 在python提示符里 help(str) python基于 ...

  4. Python格式化字符串和转义字符

    地址:http://blog.chinaunix.net/uid-20794157-id-3038417.html Python格式化字符串的替代符以及含义     符   号     说     明 ...

  5. [转载] python 计算字符串长度

    本文转载自: http://www.sharejs.com/codes/python/4843 python 计算字符串长度,一个中文算两个字符,先转换成utf8,然后通过计算utf8的长度和len函 ...

  6. Python基础-字符串格式化_百分号方式_format方式

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  7. python判断字符串

    python判断字符串 s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小 ...

  8. Python格式化字符串

    在编写程序的过程中,经常需要进行格式化输出,每次用每次查.干脆就在这里整理一下,以便索引. 格式化操作符(%) "%"是Python风格的字符串格式化操作符,非常类似C语言里的pr ...

  9. python(七)字符串格式化、生成器与迭代器

    字符串格式化 Python的字符串格式化有两种方式:百分号方式.format方式 1.百分号的方式 %[(name)][flags][width].[precision]typecode (name) ...

随机推荐

  1. ZeroClipboard.swf

    ZeroClipboard.config({             moviePath: "source/ZeroClipboard.swf",             hove ...

  2. IntelliJ插件安装

    1. 插件管理器在线安装 在IntelliJ插件管理页面([FileàSettingsàIDE SettingsàPlugins]),点击[Browse repositories-]按钮,在搜索框内输 ...

  3. PHP如何解决网站大流量与高并发的…

    首先,确认服务器硬件是否足够支持当前的流量. 普通的P4服务器一般最多能支持每天10万独立IP,如果访问量比这个还要大, 那么必须首先配置一台更高性能的专用服务器才能解决问题 ,否则怎么优化都不可能彻 ...

  4. 28、Jquery 页面效果

    Jquery动画函数分为三类 基本动画函数 基本动画函数包括show(显示).hide(隐藏).toggle(切换)这三个函数. 例子所需html <input type="butto ...

  5. 让Sql语句区分大小写

    除非你使用 LIKE 来比较字符串,否则MySQL的WHERE子句的字符串比较是不区分大小写的. 你可以使用 BINARY 关键字来设定WHERE子句的字符串比较是区分大小写的. SELECT * f ...

  6. DBNull与Null

    DBNull与Null的区别在于,DBNull代表该字段在数据库中根本不存在,Null代表该字段在数据库中没有值.

  7. c语言学习之基础知识点介绍(八):函数的基本用法

    本节开始说函数. 一.函数的基本用法  /* 作用:可以实现代码的复用,在一定程度上解决代码冗余的问题:方便后期维护. 语法: void 函数名(){ 函数体; } 函数命名要有意义,遵守驼峰命名法. ...

  8. asp IIS部署An error occurred on the server when processing the URL错误提示解决

    An error occurred on the server when processing the URL. Please contact the system administrator.If ...

  9. Java验证码代码

    public class VerifyCodeController { private int width = 90;//定义图片的width private int height = 20;//定义 ...

  10. APP启动页

    关于APP启动引导页面模块 时间:2016年6月14日 作者:赵锐 模块使用说明 模块暴露在外的接口是- (void)showGuideViewWithImages:(NSArray *)images ...