1) Text 파일 : 문자열, 메모장으로 열렸을 때, 표시가 제대로 됨. 파이썬 , html
2) Binary 파일 : 이진법, 엑셀, 워드, 메모장으로 열었을 때, 이상한 문자 , 어플리케이션에 종속되어 있다.
f= open("<파일명>","<접근모드>")
f.close()
f=open(".txt", "r")
data = f.read()
f.close()
with open(".txt","r") as file:
data=file.read()
print(type(data),data)
with open(".txt","r") as file:
data=file.readlines()
word= data.split(" ")
line= data.split("\n")
print(type(data),data)
with open(".txt","r") as file:
i=0
while Ture:
line =file.realine()
if not line:
break
print(str(i) +line.replace("\n",""))
i=i+1
f= open(".txt",'w',encoding="utf8")
for i in range(1,11):
data ="%d번재 줄\n" %i
f.write(data)
f.close()
with open(".txt",'a',encoding="utf8") as f:
for i in range(1,11):
data ="%d번재 줄\n" %i
f.write(data)
(출처 : https://www.bbc.co.uk/food/recipes/cucumber_and_dill_fridge_43183)
import pickle
# 저장
f =open("lst.pickle","wb")
test=[1,2,3]
pickle.dump(test,f) # test 를 f에 저장
f.close()
# 불러오기
f =open("lst.pickle", "rb")
load_pickle =pickle.load(f)
f.close()