喵宅苑 MewoGarden × 技术宅社区II | Z站 Z Station 棒棒哒纯文字二次元技术社区

正文

在信息储存上有点问题解决不了

作者:暮零天晨
[i=s] 本帖最后由 绯色の胖子 于 2015-6-12 18:13 编辑 在看完简明python后尝试着做最后的那个通讯录 在信息储存上有点问题解决不了 #!/usr/bin/python #Filename : Directory inquirles import cPickle as p class Person_Address: def __init__(self,name,group,phone_number,email_address): self.name = name self.group = group self.phone_number = phone_number self.email_address = email_address def Print_message(self): '''It is a message print function in class print a person's name,group,phone number,email address''' print self.name,self.group,self.phone_number,self.email_address direct = {} Storedfile = '/home/licht/Documents/MessageBook' def add_new(): '''It is a new person message append function''' direct['licht'] = Person_Address('licht','family','132','3628') name = raw_input("Please inpute the person's name:") group = raw_input("Please inpute the person's group:") number = raw_input("Please inpute the person's phone numbr:") email = raw_input("Please inpute the person's email address:") direct[name] = Person_Address(name,group,number,email) #这里,类被存储到字典里时是存成 {'licht':<__main__.Person_Address instance at 0x20d6680>} f_temp = file(Storedfile,'ab') p.dump(direct,f_temp) f_temp.close() def search_one(): '''It is a person message search function''' name = raw_input("Please inpute the person's name:") f_temp = file(Storedfile,'rb') while True: try: store = p.load(f_temp) #在这里被取出来后还是{'licht': <__main__.Person_Address instance at 0x20d6680>},怎么能才能让它取出以后是可以正常输出信息? if store.has_key(name): print store break except EOFError: break if __name__ == '__main__': add_new() search_one() 还求大神赐教! 更多 0

回复

本帖最后由

作者:neuront
[i=s] 本帖最后由 neuront 于 2014-7-17 18:06 编辑 楼主你所谓的「正常输出信息」是不是指在 [mw_shl_code=python,true]person = Person_Address(...) print person # 这里[/mw_shl_code] 输出的时候产生的内容是定义在 Print_message 里的那种, 而不是一串 <__main__.Person_Address instance at 0x20d6680> 这样的东西? 如果是这样的话你需要覆盖 __str__(self) 这个函数.
查看回复
上一页
下一页
0%
站点地图友情链接:
喵宅苑
喵空间社区程序
喵宅苑 静态版
宅喵RPG地图编辑器
络合兔
Lanzainc
技术宅
小五四博客
莉可POI
Mithril.js
枫の主题社
Project1
午后少年
机智库
七濑胡桃
xiuno
幻想の日常
魂研社
Nothentai
0xffff
欲望之花
泽泽社长
淀粉月刊
HAYOU
红客联盟
异次元
轻之国度
神奇宝贝新生代
游戏狗
口袋双子星
我的世界论坛
梦次元
动漫东东
动漫国际
精艺论坛
78动漫
吐槽弹幕网
漫客栈