TOC
With 문
1. pickle을 이용하는 방법
- file의 정보를 읽어와서 변수에 저장하는 방법
- with open("file", "rb") as variable:
- with 문을 탈출하면서 profile.pickle file을 종료하므로 따로 .close() 문을 쓸 필요 없다.
import pickle
with open("profile.pickle", "rb") as profile_file:
print(pickle.load(profile_file))
2. pickle이 아닌 일반 파일을 이용하는 방법 - 덮어쓰기
with open("study.txt", "w", encoding="utf8") as study_file:
study_file.write("파이썬을 열심히 공부하고 있어요.")
3. pickle이 아닌 일반 파일을 이용하는 방법 - 불러오기
with open("study.txt", "r", encoding="utf8") as study_file:
print(study_file.read())
Reference