728x90
반응형
[io05_pickling]
import pickle
score = {'name': 'kh', 'kor':100, 'eng':60, 'math': 80}
with open('test02.txt','wb') as file:
pickle.dump(score, file)
'''
pickling : 객체 -> 파일
unpickling: 파일 -> 객체
'''
객체가 파일로 변환되어 바이너리코드로 저장되면서 위와 같이 내용이 저장된다.
[io06_pickling된 파일 읽기]
import pickle
file = open('test02.txt', 'rb')
score = pickle.load(file)
print(score)
print(type(score))
file.close()
# 결과값
{'name': 'kh', 'kor': 100, 'eng': 60, 'math': 80}
<class 'dict'>
728x90
반응형
'Language > Python' 카테고리의 다른 글
[python]crawling_크롤링_naver02 (0) | 2020.10.12 |
---|---|
[python]crawling_크롤링_naver01 (0) | 2020.10.12 |
[python]io_file_r,w,a,x (0) | 2020.10.12 |
[python]math_원의 넓이 (0) | 2020.10.12 |
[python]numpy, matplotlib_그래프 (0) | 2020.10.12 |