# -*- coding: cp936 -*-
import os
import cpickle as p
class person:
def __init__(self,name,age,***):
self.name=name
self.age=age
self.***=***
def __str__(self):
return "name:"+self.name+" ,age:"+self.age+" ,***:"+self.***
class ab:#addressbook
def __init__(self):
pass
def add(self,person):
self.ab[person.name]=person
print 'new person added!'
def delete(self,name):
try:
del self.ab[name]
print 'deleted! %s' % name
except:
print 'delete %s failed!' % name
def find(self,name):
print self.ab.get(name,"not find!")
def show(self):
for name,person in self.ab.items():
print person.name+" "+person.age+" "+person.***
global abook
a_book_dir="ab.data"
abook=ab()
abook.ab={}
print '''<------------------>\n
author: mason \n
version: 1.0 \n
date: 11/5/2011 \n
<------------------>'''
while true:
print "<------------------>"
print "a:add a person"
print "d:del a person"
print "l:list all person"
print "f:find a person by name"
print "<------------------>"
cmd=raw_input("輸入命令:")
if cmd=='a':
print "input like this: name age ***"
s=raw_input("person info:")
info=s.split(" ")
print info
person=person(info[0],info[1],info[2])
abook.add(person)
elif cmd=='d':
name=raw_input("input name:")
abook.delete(name)
elif cmd=='l':
abook.show()
elif cmd=='e':
break
elif cmd=='f':
abook.find(raw_input("name:"))
f= open("a_book_dir",'w')
p.dump(abook.ab,f)
f.close()
print "thanks 4 using ab!"
實現乙個python初學者應該練習的通訊錄功能,a、d、l、f功能。最終退出程式的時候講通訊錄儲存在a_book_dir檔案中。 MVC面試第一版
mvc流程 1 使用者向伺服器傳送請求,請求被springmvc 前端控制器 dispatcherservlet 捕獲 2 dispatcherservlet對請求url進行解析,得到請求資源識別符號 uri 4 dispatcherservlet 根據獲得的handler,選擇乙個合適的handl...
HomePlay第一版demo發布
一直想做乙個能夠方便跨平台開發的應用框 基礎部分已經完成,於是將這個處於襁褓中的框架應用在win32基礎之上,花了些功夫研究了ffmpeg的使用,做了乙個demo,發布出來吸引批評與建議。框架基礎部分用c語言開發,以dll方式封裝了核心功能以及對ffmpeg的使用部分。出於簡單考慮,外部採用mfc包...
C Socket程式設計步驟 第一版
1 server端 include include pragma comment lib,ws2 32.lib voidmain if lobyte wsadata.wversion 1 hibyte wsadata.wversion 1 socket socksrv socket af inet,...