1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#!/usr/bin/env python # coding=utf-8 import cPickle as p import sys import os class Person(): def __init__(self,name,tel,userlist): self.name = name self.tel =tel self.userlist=userlist def AddToList(self): if self.userlist.has_key(self.name): print 'Already have this one will change' anser = raw_input('Please input Y/N:') if anser == 'Y': self.userlist[self.name] = self.tel else: pass else: self.userlist[self.name] = self.tel return self.userlist class UserList(): def __init__(self,listname): self.listname = listname def getStored(self): if os.path.isfile(self.listname): #this already have one f = file(self.listname) self.storedlist = p.load(f) f.close() else: f = open(self.listname,'w+') f.close return self.storedlist if __name__ == '__main__' : storedname='first' L = UserList(storedname) Oldlist=L.getStored() name = raw_input('Please input the name:') tel = raw_input('Please input the tel:') p1=Person(name,tel,Oldlist) newlist=p1.AddToList() print newlist f = file(storedname,'w') p.dump(newlist,f) f.close |
第一版
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021
bateer 2015/11/10 20:07
从百度点进来的,支持一下