一个简单的脚本程序----Python
1.
#!/usr/bin/python3.3
import cPickle as p
#the class of people information
class People:
def __init__(self,ID,name,age,address):
self.ID=ID
self.name=name
self.age=age
self.address=address
def printName(self):
print(self.name)
def printAddress(self):
print(self.name+"---"+self.address)
#Create two people
a=People(1,"yufeng",24,"HUST")
b=People(2,"luqun",23,"XianDianzi")
#Create a dictionary for people
dict1={1:a,2:b}
#Write to the file
f=file("people_info.txt",'w')
#dump the object to a file
p.dump(dict1,f)
f.close()
f=file("people_info.txt")
dict2=p.load(f)
print(dict2[1].printAddress())