open("파일명","모드")
f= open("test.txt","w",encoding="utf-8")
w: 쓰기모드
r: 읽기모드
a: 추가모드
f.write("내용")
f.close()
파일의 첫번째 줄만 출력
d= open('test.txt',"r",encoding="utf-8")
readData= d.readline()
print(readData)
d.close()
파일의 모든 줄을 읽어서 각각의 줄을 요소로 갖는 리스트를 반환
d= open('test.txt',"r",encoding="utf-8")
readData= d.readlines()
for i in readData:
print(i)
d.close()
파일의 내용 전체를 문자열로 반환
d= open('test.txt',"r",encoding="utf-8")
readData= d.read()
print(readData)
d.close()