重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
phonebook = {
公司主营业务:成都做网站、成都网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出龙湾免费做网站回馈大家。
'Alice':{
'phone':'2341',
'addr':'Foo drive 23'
},
'Beth':{
'phone':'1213',
'addr':'Baz avenue 90'
},
'Ceil':{
'phone':'3219',
'addr':'Baz avenue 90'
}
}
key=input("请输入您要查找的姓名:")
#for key in phonebook:
if key in phonebook.keys():
print (phonebook[key])
else:
print("没有 ",key,' 的信息')
#用python 3.4改的,个别函数可以自行替换
只靠python拿不到手机通话记录,还需要拥有手机通讯录权限才可以。调用安卓的java接口。
自己实现一个排序的dict,python文档上好像都有一个例子,
pcike模块保存到文件
我做的,文件信息保存在excel文件中,希望能帮助你,添加功能只需模仿就可以了
# -*- coding: cp936 -*-
import wx
import os
import copy
from mytools import Excell
wildcard = "note source (*.xsl)|*.xls|"\
"All files (*.*)|*.*"
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,"account input")
self.panel = wx.Panel(self)
self.topLbl = wx.StaticText(self.panel,-1,"帐户信息")
self.topLbl.SetFont(wx.Font(18,wx.SWISS,wx.NORMAL,wx.BOLD))
self.nameLbl = wx.StaticText(self.panel,-1,"姓名:")
self.name = wx.TextCtrl(self.panel,-1,"阮班勇")
self.addrLbl = wx.StaticText(self.panel,-1,"地址:")
self.addr = wx.TextCtrl(self.panel,-1,"")
self.addr2 = wx.TextCtrl(self.panel,-1,"")
self.cstLbl = wx.StaticText(self.panel,-1,"市,县,村:")
self.city = wx.TextCtrl(self.panel,-1,"")
self.state = wx.TextCtrl(self.panel,-1,"")
self.zip = wx.TextCtrl(self.panel,-1,"")
self.phoneLbl = wx.StaticText(self.panel,-1,"电话:")
self.phone = wx.TextCtrl(self.panel,-1,"")
self.qqLbl = wx.StaticText(self.panel,-1,"QQ:")
self.qq = wx.TextCtrl(self.panel,-1,"")
self.emailLbl = wx.StaticText(self.panel,-1,"Email:")
self.email = wx.TextCtrl(self.panel,-1,"")
self.saveBtn = wx.Button(self.panel,-1,"保存")
self.Bind(wx.EVT_BUTTON,self.OnSave,self.saveBtn)
self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
self.cancelBtn = wx.Button(self.panel,-1,"删除")
self.Bind(wx.EVT_BUTTON,self.OnCancel,self.cancelBtn)
self.saveAsBtn = wx.Button(self.panel,-1,"新建")
self.Bind(wx.EVT_BUTTON,self.OnSaveAs,self.saveAsBtn)
self.exitBtn = wx.Button(self.panel,-1,"退出")
self.Bind(wx.EVT_BUTTON,self.OnExit,self.exitBtn)
self.data = {"姓名":1,"地址":2,"市":3,"县":4,"村":5,
"电话":6,"QQ":8,"email":7}
self.dataStr="姓名 地址 市 县 村 电话 QQ email".split()
self.olddata={"1":1}
self.row = 2
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(self.topLbl,0,wx.ALL,5)
mainSizer.Add(wx.StaticLine(self.panel),0,wx.EXPAND|wx.TOP|wx.BOTTOM,5)
addrSizer = wx.FlexGridSizer(cols=2,hgap=5,vgap=5)
addrSizer.AddGrowableCol(1)
addrSizer.Add(self.nameLbl,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(self.name,1,wx.EXPAND)
addrSizer.Add(self.addrLbl,1,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(self.addr,1,wx.EXPAND)
addrSizer.Add((10,10))
addrSizer.Add(self.addr2,1,wx.EXPAND)
addrSizer.Add(self.cstLbl,1,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
cstSizer = wx.BoxSizer(wx.HORIZONTAL)
cstSizer.Add(self.city,1)
cstSizer.Add(self.state,0,wx.LEFT|wx.RIGHT,5)
cstSizer.Add(self.zip,)
addrSizer.Add(cstSizer,1,wx.EXPAND)
addrSizer.Add(self.phoneLbl,1,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(self.phone,1,wx.EXPAND)
addrSizer.Add(self.qqLbl,1,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(self.qq,1,wx.EXPAND)
addrSizer.Add(self.emailLbl,1,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(self.email,1,wx.EXPAND)
mainSizer.Add(addrSizer,0,wx.EXPAND,10)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer.Add((20,20),1)
btnSizer.Add(self.saveBtn)
btnSizer.Add((20,20),1)
btnSizer.Add(self.saveAsBtn)
btnSizer.Add((20,20),1)
mainSizer.Add(btnSizer,0,wx.EXPAND,15)
btnSizer2 = wx.BoxSizer(wx.HORIZONTAL)
btnSizer2.Add((20,20),1)
btnSizer2.Add(self.cancelBtn)
btnSizer2.Add((20,20),1)
btnSizer2.Add(self.exitBtn)
btnSizer2.Add((20,20),1)
mainSizer.Add(btnSizer2,1,wx.EXPAND|wx.BOTTOM,10)
self.panel.SetSizer(mainSizer)
mainSizer.Fit(self)
mainSizer.SetSizeHints(self)
self.bFirst = True
self.created = False
def OnSave(self,event):
if self.bFirst and not self.created:
dlg = wx.FileDialog(self, message="Save file as ...", defaultDir=r'D:\My Documents',
defaultFile="", wildcard=wildcard, style=wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.myExcell = Excell.easyExcel(path)
else:
return
self.bFirst = False
row = self.myExcell.getEmptyRow("sheet1")
self.row = row
self.saveData()
def saveData(self):
self.data["姓名"] = self.name.GetValue()
self.data['地址'] = self.addr.GetValue()
self.data['市'] = self.city.GetValue()
self.data['县'] = self.state.GetValue()
self.data['地址'] += self.addr2.GetValue()
self.data['村'] = self.zip.GetValue()
self.data['电话'] = self.phone.GetValue()
self.data['email'] = self.email.GetValue()
self.data['QQ'] = self.qq.GetValue()
bsave = True
if self.olddata == self.data:
t = wx.MessageBox("与上次数据相同是否保存?",style=wx.OK|wx.CANCEL)
print t
if t == wx.CANCEL:
bsave = False
if bsave and self.data["姓名"] == u"阮班勇":
t = wx.MessageBox("你是DOC阮吗,真的要保存他吗?",style=wx.OK|wx.CANCEL)
print t
if t == wx.CANCEL:
bsave = False
if bsave :
self.olddata =copy.copy( self.data)
wx.MessageBox("保存成功!")
col = 1
for value in self.dataStr:
self.myExcell.setCell('sheet1',1,col,value)
self.myExcell.setCell('sheet1',self.row,col,self.data[value])
col +=1
self.myExcell.save()
self.row+=1
def OnCloseWindow(self,event):
if not self.bFirst:
self.myExcell.close()
print 'dedeted'
self.Destroy()
def OnCancel(self,event):
self.name.SetValue("")
self.addr.SetValue("")
self.addr2.SetValue("")
self.city.SetValue("")
self.state.SetValue("")
self.zip.SetValue("")
self.qq.SetValue("")
self.phone.SetValue("")
self.email.SetValue("")
def OnSaveAs(self,event):
dlg = wx.FileDialog(
self, message="Save file as ...", defaultDir=r'D:\My Documents', wildcard=wildcard, style=wx.SAVE)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.myExcell = Excell.easyExcel()
self.created = True
self.myExcell.save(path)
self.saveData()
def OnExit(self,event):
self.Close(True)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame =TestFrame()
frame.Show()
app.MainLoop()
可以将数据存储在列表里
然后再将列表保存到文件里
通过对列表的操作动态更改存储在文件里的内容
如果有文件的话程序启动时从文件里加载数据保存到列表即可
如果代码不想自己写的话
我可以有偿代劳
friend={ '小明':['001', '广州'],'小红':['002','深圳'],'小王':['003','北京']}
model=input("model:")
if model=='1':
print("好友添加:",end='')
new_friend=input("newfriend:name,number,address")
friend_n=list(new_friend.split(','))
friend[friend_n[0]] =friend_n[1:3] # 添加
# friend4=dict.fromkeys([friend_n[0]],friend_n[1:3])
print("friend: ", friend)
elif model=='2':
print("好友删除:",end='')
new_friend = input("name")
# del friend[ new_friend] # 删除键是'Name'的条目
try:
friend.pop(new_friend)
print("friend: ", friend)
except:
print("查无此人")
elif model=='3':
print("好友修改:", end='')
new_friend = input("name")
friend[new_friend]=list(input("number,address").split(','))
print("friend: ", friend)
else:
print("好友查询:", end='')
new_friend = input("name")
try:
print(new_friend,':', friend[new_friend])
except:
print("查无此人")
以上程序包含了整个流程,有删赠改查功能,还有利用异常处理的处理过程。