这个是之前写的半成品,但是一直没有好好的写完,今晚我把它补充完整,并且贴出了遇到的问题

这个程序并没有处理中文,主要是python 2.7对于中文的支持太蛋疼了,虽然可以设置utf8编码,但是如果列表中的某个变量是中文的话,打就会打印出那种我看不懂的编码,我干脆懒得理了,我想自己用python来处理中文的需求基本没有,可能以后就是用python谢谢程序玩玩而已

#!/usr/bin/python
# -*- coding: utf-8 -*-
from os import system
system("clear") def menu():
print "\t Welcome to the Information Management Center"
print "\t\t\t1.Add user"
print "\t\t\t2.View information"
print "\t\t\t3.Delete user"
print "\t\t\t4.Display all information" def search():
flag=0
username=raw_input('Please enter the name that you wanna view: ')
print info.get(username,'Sorry,i can not find it')
raw_input('Press enter to continue')
def add():
name=raw_input('NAME: ')
for temp in info:
if name==temp:
raw_input('The name you enterd already exist!(Press enter to continue)')
return
birth=input('BIRTHDAY: ')
job=raw_input('OCCUPATION: ')
info[name]=(birth,job)
print 'done'
raw_input('Press enter to continue')
def delete():
flag=0
name=raw_input('Enter the name what you want to delete: ')
#for temp in info:这样迭代并且删除有问题
for temp in info.keys():
if name==temp:
flag=1
del info[name]
print 'done'
raw_input('Press enter to continue')
if flag==0:
print 'I can not find the user.'
raw_input('Press enter to continue')
def showall():
flag=0
for name in info:
flag=1
print name,info[name]
if flag==0:
print 'No data'
raw_input('Press enter to continue') info={}
info['tcstory']=(1993,"student")
while 1:
menu()
try:
choice=input("Enter your choice(q to quit): ")
if int(choice)!=choice and abs(choice)+choce==0:
print 'Please enter the correct option\n'
system("clear")
continue
except (NameError,ValueError,SyntaxError): #syntaxerror 是为了防止一开始就直接输入回车键引起的错误
print "OKey,goodbye!"
break
if choice==1:
add()
system('clear')
elif choice==2:
search()
system('clear')
elif choice==3:
delete()
system('clear')
elif choice==4:
showall()
system('clear')
else:
print 'Your choice is invalid.'

之前遇到了一个问题,就是删除某个键的时候出错了

百度了一下,这个博客给出了解决的方法

http://www.cnblogs.com/codeape/archive/2012/11/21/2780534.html

接下来我还要对这个程序进行修改,1.把所用到的函数放入一个模块中,2.从文件中读取数据和吧数据写入文件中

这个是明天的工作,今晚还要学习english和看python 的模块和文件操作部分,并且还要看一下vim 中syntaxtic 的插件的使用方法

python 小试牛刀之信息管理的更多相关文章

  1. Python 小试牛刀,Django详细解读,让你更快的掌握它!!!

    一.MVC和MTV模式 MVC:将web应用分为模型(M),控制器(C),视图(V)三层:他们之间以一种插件似的,松耦合的方式连接在一起. 模型负责业务对象与数据库的对象(ORM),视图负责与用户的交 ...

  2. 【Python小试牛刀】循环

    1.斐波那契数列 斐波那契数列,数列前两项为1,之后每一项都是前两项之和. #!/usr/bin/env python3 a, b = 0, 1 while b < 100: print(b) ...

  3. 新手Python第二天(存储)

    Python 列表的创建 创建一个空列表 例如:fruit=[]  创建一个有元素的列表 例如:fruit=['apple','banana','cherry'] 创建嵌套列表 例如:fruit=[[ ...

  4. Python函数案例——员工信息管理

    员工信息管理 简单的员工信息增删改查程序 表信息 1,Alex Li,22,13651054608,IT,2013‐04‐01 2,Jack Wang,28,13451024608,HR,2015‐0 ...

  5. Python + Robotframework + Appium 之APP自动化测试小试牛刀(Android)

    Robotframework如何好?这里先不说了~ Python更不用说了~ Appium前面的文章有介绍~ 今天直接来Python+Robotframework+Appium 三者结合起来,对And ...

  6. Python&R:警告信息管理

    计算机程序有时很人性化,比如给你警告提示信息: 计算机程序有时又非常不人性化,比如动不动就给你警告提示...... 如果你的程序是要给客户使用,有运行美化要求: 再尤其是比如警告出现在循环里的情况,那 ...

  7. 初试Python语法小试牛刀之冒泡排序

    Python很火,心里很慌,没吃过猪肉,也要见见猪走路. 看了几天Python的语法,大概初步了解了一点点,https://www.liaoxuefeng.com/wiki/0014316089557 ...

  8. Python爬虫之小试牛刀——使用Python抓取百度街景图像

    之前用.Net做过一些自动化爬虫程序,听大牛们说使用python来写爬虫更便捷,按捺不住抽空试了一把,使用Python抓取百度街景影像. 这两天,武汉迎来了一个德国总理默克尔这位大人物,又刷了一把武汉 ...

  9. 小试牛刀——python接口测试小框架

    用例设计: 执行用例代码: # -*- coding: UTF-8 -*-import xlrd,logging,urllib,urllib2,json,sysfrom pylsy import py ...

随机推荐

  1. Android中style的使用

    摘自搜搜问问. <item name="#1">#2</item> 1.item 的name属性#1可以为所有系统所带组件的属性,#2为此属性的值如andr ...

  2. 【Delphi】注册快捷键

    ShortCutToText , TextToShortCut 需 uses Menus; type TForm1 = class(TForm) HotKey1: THotKey; Button1: ...

  3. html/css 盒子布局 Margin 、Padding 、border 以及 清除浮动的知识 (学习HTML过程中的小记录)

    html/css  盒子布局 Margin .Padding .border 以及 清除浮动的知识 (学习HTML过程中的小记录) 作者:王可利(Star·星星) width     是"宽 ...

  4. spring与mysql整合数据源的配置

    需要解决两点,数据源的配置交给spring完成,事务管理交个spring来管理. <context:property-placeholder location="classpath:c ...

  5. spring 方法注入

    package com.haut.grain.junit.test; public  class Command {private Object state;public void setState( ...

  6. Redbean:入门(四) - 反射机制 以及 事务

    <?php //引入rb入口文件 include_once 'rb.php'; //定义dsn以及相关的数据 $dsn = 'mysql:host=localhost;dbname=hwibs_ ...

  7. Android SharedPreferences使用以及原理详解

    SharedPreferences的使用非常简单,能够轻松的存放数据和读取数据.SharedPreferences只能保存简单类型的数据,例如,String.int等.一般会将复杂类型的数据转换成Ba ...

  8. Oracle用户,权限,角色以及登录管理 scoot 授权

    Oracle用户,权限,角色以及登录管理 1. sys和system用户的区别 system用户只能用normal身份登陆em.除非你对它授予了sysdba的系统权限或者syspoer系统权限. sy ...

  9. SQL开发技巧(二) 【转】感觉他写的很好

    本文转自: http://www.cnblogs.com/marvin/p/DevelopSQLSkill_2.html 本系列文章旨在收集在开发过程中遇到的一些常用的SQL语句,然后整理归档,本系列 ...

  10. js贪吃蛇

    function init() { w = 40; m = 20; d = w * m / 2; food = null; dm = new ht.DataModel(); g3d = new ht. ...