NOTES/PYTHON
Python dictionary 저장/불러오기
chargingport
2023. 9. 5. 11:12
반응형
import pickle
dict = {'A': 1, 'B': 2, 'C': 3}
# dictionary를 dictionary.pkl에 저장
with open("dictionary.pkl", "wb") as output_file:
pickle.dump(dict, output_file)
# dictionary.pkl을 dictionary로 저장
with open("dictionary.pkl", "rb") as input_file:
newDict = pickle.load(input_file)
print(newDict)
$ python3 main.py
{'A': 1, 'B': 2, 'C': 3}
반응형