[ 오늘의 수업내용 요약 ]
036_ 텍스트파일 열기 모드
037_ with~as문
with~as문을 이용하면 파일닫기(close)를 생략할 수 있다.
file = open(uri + ‘5_037.txt, ’a’)
file.write(‘python study’)
file.close()
=> with open(wri + ‘5_037.txt.’, ‘a’) as f:
f.write(‘python study’)
038_ writelines()
languages = [‘c/c++’, ‘java’, ‘c#’, ‘python’, ‘javascript’ ]
uri = ‘C:/pythonTxt/’
with open(uri + ‘languager.tct’, ‘a’) as f:
f.writelines(languages)
039_ readlines(), readline()
1. readlines()
: 파일의 모든 데이터를 읽어서 리스트 형태로 반환한다.
2. readline()
: 한 행을 읽어서 문자열로 반환한다.