7. with

2023. 5. 8. 20:14python

pickle 읽기

import pickle

with open("profile.pickle", "rb") as profile_file:
	print(pickle.load(profile_file))

# close 를 안해도됨

'''
{"이름": "박명수", "나이":30, "취미":["축구", "골프", "코딩"]}
'''

쓰기

with open("study.txt", "w", encoding="utf8") as study_file:
	study_file.write("파이썬을 열심히 공부하고 있어요")

# study.txt 파일이 생긴다.

읽기

with open("study.txt", "r", encoding="utf8") as study_file:
	print(study_file.read())

# 파이썬을 열심히 공부하고 있어요

'python' 카테고리의 다른 글

7. 퀴즈 #7  (0) 2023.05.08
7. pickle  (0) 2023.05.08
7. 파일 입출력  (0) 2023.05.08
7. 다양한 출력 포멧  (0) 2023.05.08
7. 표준입출력  (0) 2023.05.08