# 객체 저장import pickle def obWrite(): myList = [10,20,30,40] fp = open("ob.txt", "wb") pickle.dump(myList, fp) fp.close() def obRead(): fp = open("ob.txt", "rb") my = pickle.load(fp) fp.close() print(my) obWrite() obRead()
# sqlite db에 키, 값 저장 (딕셔너리와 유사)import shelve def shelveWrite(): sh = shelve.open('my') # my.dat DB에 저장 되는 것임. sh['name'] = '홍길동' sh['age'] = 20 sh['data'] = [10, 20, 30,40] sh.close() def shelveRead(): sh = shelve.open('my') sh.pop('name') # 삭제 for s in sh: print(s, sh[s]) shelveWrite() shelveRead()
댓글 없음:
댓글 쓰기