python 简单的信息管理系统

 #!/usr/bin/python
 #coding=utf-8
 import io
 import os
 import time

 FileRead  = io.open('callingcard','r',encoding='utf8')
 FileWrite = open('callingcard_copy','w+')
 CallingCard = eval(FileRead.read())

 def Judge(chioce):
     ': CallingCard_Append()
     ': CallingCard_Chance()
     ': CallingCard_del()
     ': CallingCard_Look()
     ': CallingCard_All()
     ': exit()
     elif chioce == 'c' or chioce == 'C': CallingCard_Chance()
     elif chioce == 'L' or chioce == 'l': CallingCard_Look()
     elif chioce == 'a' or chioce == 'A': CallingCard_Append()
     else :
         chioce = raw_input('你的输入有误 请重新输入')
         Judge(chioce)

 def CallingCard_Append():
     name   = raw_input('请输入姓名:\n')
     qq     = raw_input('请输入qq号:\n')
     wechat = raw_input('请输入微信号:\n')
     tel    = raw_input('请输入电话号码:\n')
     add    = raw_input('请输入地址:\n')
     CallingCard[name] = {}
     CallingCard[name]['QQ'] = qq
     CallingCard[name]['微信'] = wechat
     CallingCard[name]['电话'] = tel
     CallingCard[name]['住址'] = add
     print '已经添加成功'
     ExChange()

 def CallingCard_del():
     name = raw_input('请输入你要删除的名片:\n')
     if name not in CallingCard:
         print '你输入的用户不存在\n'
         CallingCard_del()
     else:
         CallingCard.pop(name)
         print '已成功删除'
     ExChange()

 def CallingCard_Chance():
     name = raw_input('请输入你要修改的名片:\n')
     if name not in CallingCard:
         print '你输入的名片不存在,'
         Button = raw_input('请输入正确的名字(C)或查看所以名片(L)\n')
         Judge(Button)
     else :
         chioce = raw_input('请输入你要修改的项目(姓名/QQ/微信/电话/地址):\n')
         content = raw_input('请输入你要替换的内容:\n')
         if chioce == '姓名':
             CallingCard[content] = CallingCard[name]
             CallingCard.pop(name)
         else :
             CallingCard[name].pop(chioce)
             CallingCard[name][chioce] = content

     ExChange()

 def CallingCard_Look():
     name = raw_input('请输入你要查看的用户:\n')
     if name not in CallingCard:
         print '你输入的用户不存在\n'
         choice = raw_input('请按L重新查询或者按A新增一个用户\n')
         Judge(choice)
     else :
         print '='*43,'Info of %s'%name,'='*43
         str ='''
         姓名:%s
         电话:%s
         QQ号:%s
         微信号:%s
         地址:%s
         '''
         print str %(name,CallingCard[name]['QQ'],CallingCard[name]['微信'],CallingCard[name]['电话'],CallingCard[name]['住址'])
     ExChange()

 def CallingCard_All():
     print '='*42,'用户信息管理系统','='*42
     num = 1
     str = '''
     编号:%s 姓名:%s QQ:%s 微信号:%s 电话:%s 地址:%s
     '''
     for i in CallingCard:
         print str %(num,i,CallingCard[i]['QQ'],CallingCard[i]['微信'],CallingCard[i]['电话'],CallingCard[i]['住址'])
         num += 1
     time.sleep(5)
     MenuShow()

 def ExChange():
     global FileWrite,FileRead
     CallingCardCopy = str(CallingCard)
     FileWrite.write(CallingCardCopy)
     FileWrite.close()
     FileRead.close()
     os.remove('callingcard')
     os.renames('callingcard_copy','callingcard')
     FileRead = io.open('callingcard', 'r', encoding='utf8')
     FileWrite = open('callingcard_copy', 'w+')
     time.sleep(5)
     MenuShow()

 def MenuShow():
     print '='*42,'用户信息管理系统','='*42
     print '[1]添加一个新的用户        [2]删除一个用户'
     print '[3]修改一个用户的信息      [4]查询一个用户'
     print '[5]显示所以的用户         [6]退出'
     chioce = raw_input('请输入你的选项\n')
     Judge(chioce)

 MenuShow()

选择判断模块还可以更简单一点,just so

上一篇:Android调用相机实现拍照并裁剪图片,调用手机中的相冊图片并裁剪图片


下一篇:android 拍照上传文件 原生定位