+ -
当前位置:首页 → 问答吧 → cPickle的问题?

cPickle的问题?

时间:2011-04-27

来源:互联网

import sys
import time
try:
  import cPickle as p
except:
  import Pickele as p
class contact:
  def __init__(self,name,phone):
  self.name=name
  self.phone=phone
  list=[self.name,self.phone]
  listdicts={}
  listdicts['name']='phone'
  cont="ms.log"
  f=file(cont,"a+")
  p.dump(listdicts,f)
  f.close()
  listdicts.clear()
def inputinfo():
  while True:
  name=raw_input("Enter name:")
  phone=raw_input("Enter phone number:")
  forsure=raw_input("Are you sure?(Y/N)")
  if forsure=="y":
  contact(name,phone)
  sys.exit()
  elif forsure=="n":
  break
  else:
  continue
def searchinfo():
  name=raw_inpout("Enter name for seach:")
  cont=file("ms.log")
  listdicts={}
  i=1
  while True:
  try:
  listdicts.update(p.load(cont))
  print "load %s times"%i
  print listdicts
  i+=1
  except EOFError:
  break
  cont.close()
  print listdicts
  print "you want search is %s"%name
  if name in listdicts:
  print listdicts['name']
  else:
  print "No found the name"
  sys.exit()
  没报错,但运行没反映
   

作者: xuzhijian17   发布时间: 2011-04-27

1,LZ没缩进。。
2,没看到调用的方法,如果你就这样写了运行,没反应是肯定滴。。把调用方法写出来。

把缩进搞好了再让人看吧。。

作者: amu9900   发布时间: 2011-04-27