您的位置:首页 > 编程语言 > Python开发

一个简单的脚本程序----Python

2014-04-10 14:44 531 查看
一个简单的脚本程序----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())
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: