一個(gè)簡單的python程序?qū)嵗?通訊錄)
核心代碼:
#!/usr/bin/python
#Filename:friendbook.py
import cPickle as p
import sys
import time
import os
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"
注:這是本人寫的第一個(gè)python,有諸多不足,以后改進(jìn)
- python實(shí)現(xiàn)通訊錄管理系統(tǒng)
- python實(shí)現(xiàn)通訊錄系統(tǒng)
- 如何用Python寫一個(gè)簡單的通訊錄
- python實(shí)現(xiàn)學(xué)生通訊錄管理系統(tǒng)
- python數(shù)據(jù)庫編程 Mysql實(shí)現(xiàn)通訊錄
- python數(shù)據(jù)庫編程 ODBC方式實(shí)現(xiàn)通訊錄
- python實(shí)現(xiàn)手機(jī)通訊錄搜索功能
- Python實(shí)現(xiàn)通訊錄功能
- Python實(shí)現(xiàn)命令行通訊錄實(shí)例教程
- python實(shí)現(xiàn)簡單通訊錄管理系統(tǒng)
相關(guān)文章
Python中ValueError報(bào)錯(cuò)的原因和解決辦法
在Python編程中,ValueError是一種非常常見的異常類型,它通常發(fā)生在函數(shù)接收到一個(gè)有效類型但不適合該函數(shù)操作的值時(shí),本文將深入探討ValueError的報(bào)錯(cuò)原因、提供詳細(xì)的解決辦法,并通過豐富的代碼示例來加深理解,需要的朋友可以參考下2024-07-07
python執(zhí)行數(shù)據(jù)庫的查詢操作實(shí)例講解
在本篇文章里小編給大家整理了一篇關(guān)于python執(zhí)行數(shù)據(jù)庫的查詢操作實(shí)例講解內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。2021-10-10
淺談Python2之漢字編碼為unicode的問題(即類似\xc3\xa4)
今天小編就為大家分享一篇淺談Python2之漢字編碼為unicode的問題(即類似\xc3\xa4),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08
Python內(nèi)建類型float源碼學(xué)習(xí)
這篇文章主要為大家介紹了Python內(nèi)建類型float源碼學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05

