• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > 一个简单的python程序实例(通讯录)

一个简单的python程序实例(通讯录)

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python程序实例,python3程序实例,python小程序实例,python脚本编写实例,python项目实例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

核心代码:

ab={'Xdex':'cneds@fnedf.com',
        'Laexly':'fev@fe.com',
        'Fukc':'fexok@ver.com',
        'Stifu':'stif@qq.com'
}


def Dumpfile(list):
        f=file(friendab,'w')
        p.dump(list,f)
        f.close()


if os.path.isfile('friendab.data'):
        friendab='friendab.data'
else:
        os.touch('friendab.data')
        Dumpfile(ab)
        del ab


f=file(friendab)
frilist=p.load(f)


class Person:
        def __init__(self,name):
                self.name=name
        def saysome(self):
                print 'The friend %s,his E-mail is %s '%(sname,frilist[sname])
class addPerson:
        def __init__(self,name,email):
                self.name=name
                self.email=email
        def addbook(self):
                ab=frilist
                ab[sname]=email
                Dumpfile(ab)
                del ab
                print 'Succlessful!'
class delPerson:
        def __init__(self,name):
                self.name=name
        def delbook(self):
                ab=frilist
                ab.pop(sname)
                Dumpfile(ab)
                del ab
                print 'Success DEL'

class alterPerson:
        def __init__(self,name,email):
                self.name=name
                self.email=email
        def alterbook(self):
                ab=frilist
                ab[sname]=email
                Dumpfile(ab)
                del ab
                print 'Succlessful update!'

print '''\
This program prints files to the standard output.
Any number of files can be specified.
Options include:
[1] : Search your friend's email from friendsbook
[2] : add your friend's email to firendsbook
[3] : del your friend's email from firnedsbook
[4] : alter your friend's email from friendsbook
[5] : All friends list
[6] : exit the program
'''


num=raw_input('Press the number [1,2,3,4,5] -->')


if (num=='1'):
        sname=raw_input('Enter the name-->')
        if sname in  frilist:
                p=Person(sname)
                p.saysome()
        else:
                print 'Not in it'
elif (num=='2'):
        sname=raw_input('Enter the name-->')
        email=raw_input('Enter the email-->')
        pa=addPerson(sname,email)
        pa.addbook()
        #p=Person(sname)
        #p.saysome()
        print frilist
elif (num=='3'):
        sname=raw_input('Enter the name-->')
        pa=delPerson(sname)
        pa.delbook()
elif (num=='4'):
        sname=raw_input('Enter the name-->')
        if sname in  frilist:
                email=raw_input('Enter the email-->')
                p=alterPerson(sname,email)
                p.alterbook()
        else:
                print 'Not in it'
elif (num=='5'):
        print frilist
elif (num=='6'):
        print "Bye!"
else:
        print "Please input the right number"
</div>

注:这是本人写的第一个python,有诸多不足,以后改进

</div>

您可能想查找下面的文章:

  • Python使用PDFMiner解析PDF代码实例
  • Python使用PDFMiner解析PDF代码实例
  • 利用python程序生成word和PDF文档的方法
  • 利用python程序帮大家清理windows垃圾
  • 实例解析Python设计模式编程之桥接模式的运用
  • Python聊天室实例程序分享
  • python插入排序算法实例分析
  • python选择排序算法实例总结
  • python实现的用于搜索文件并进行内容替换的类实例
  • python实现的简单RPG游戏流程实例

相关文章

  • Python基于DES算法加密解密实例
  • 使用 tf.nn.dynamic_rnn 展开时间维度方式
  • Python随机生成彩票号码的方法
  • Python中分数的相关使用教程
  • Python中文分词工具之结巴分词用法实例总结【经典案例】
  • python中Genarator函数用法分析
  • Python使用poplib模块和smtplib模块收发电子邮件的教程
  • python使用arcpy.mapping模块批量出图
  • python3实现抓取网页资源的 N 种方法
  • Python标准库之sqlite3使用实例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Ubuntu下创建虚拟独立的Python环境全过程
    • Python入门篇之字典
    • Python写入数据到MP3文件中的方法
    • python用来获得图片exif信息的库实例分析
    • Python中内置的日志模块logging用法详解
    • tensorflow如何继续训练之前保存的模型实例
    • 浅谈python中的实例方法、类方法和静态方法
    • python使用正则搜索字符串或文件中的浮点数代码实例
    • Python实现类似jQuery使用中的链式调用的示例
    • python实现的系统实用log类实例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有