python 电话本管理例子

python 电话本管理例子,第1张

概述python 电话本管理例子

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

#!/usr/bin/env python#Coding=utf-8#电话本管理,可以进行添加,删除,修改,查询用户信息import cPickle as p class Telephone:    def __init__(self):        '''构造方法 '''            def addPeople(self,name,email,telephone):        """添加用户"""        teleDict = self.getDictData()        if teleDict:            infoList = [name,telephone]            teleDict[name] = infoList                 self.writefile(teleDict)        else:            teleDict = {}            infoList = [name,telephone]            teleDict[name] = infoList                   self.writefile(teleDict)                    def delPeople(self,name):        """删除用户"""        teleDict = self.getDictData()        if name in teleDict.keys():            del teleDict[name]            self.writefile(teleDict)        else:            print name,'is not in dict'        def editPeople(self,emial,telephone):        """ 修改信息"""        teleDict = self.getDictData()        if name in teleDict.keys():            infoList = [name,telephone]            teleDict[name] = infoList                 self.writefile(teleDict)            print name+'edit success'        else:            print name,'is not in dict'                def getPeople(self,name):        """获取用户信息"""        teleDict = self.getDictData()        if teleDict:            if name in teleDict.keys():                people = teleDict[name]                print people            else:                print name,'is not in dict'        else:            print 'people is empty'                        def writefile(self,dictData):        """ 写入文件"""        f = file('dict.data','w')        p.dump(dictData,f)        f.close()            def getDictData(self):          """ 获取文件内容"""        filename = 'dict.data'        try:            f = file(filename)            teleDict = p.load(f)            return teleDict        except:            print 'open file error'  # 提示 信息def notice():    print "please enter 1-get people 2-add people 3-edit pelole 4-del people 5-get all people 0-break"    if __name__ == "__main__":    while(True):        notice()        userinput = int(raw_input())                people = Telephone()        if userinput == 1:            name = raw_input("please enter user name:")            people.getPeople(name)        elif userinput == 2:            name = raw_input("enter name:")            email = raw_input("enter emai:")            telephone = raw_input("enter telephone:")            people.addPeople(name,telephone)        elif userinput == 3:            name = raw_input("enter name:")            email = raw_input("enter emai:")            telephone = raw_input("enter telephone:")            people.editPeople(name,telephone)        elif userinput == 4:            name = raw_input("enter del people name:")            people.delPeople(name)        elif userinput == 5:            allpeople = people.getDictData()            if allpeople:                for key in allpeople:                    print key,allpeople[key]            else:                print 'there is no people'        elif userinput == 0:            break        else:            print 'you select number is wrong'            raw_input('press enter')                              

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的python 电话本管理例子全部内容,希望文章能够帮你解决python 电话本管理例子所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1198472.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存