read (1) 썸네일형 리스트형 파이썬 python 파일 Write 기초 예제 # chapter 08-1 # 파일 읽기 및 쓰기 # 읽기 모드 r, 쓰기모드 w, 추가 모드 a, 텍스트 모드 t, 바이너리 모드 # BUG: # 상대경로('../, ./'), 절대 경로 ('C:\Windows\...') # 파일 읽기(Read) # 예제 f = open('./resource/it_news.txt', 'r', encoding = 'UTF-8') # t는 기본값이어서 rt를 따로 적어줄 필요가 없음 # 속성확인 print(dir(f)) print() # 인코딩 확인 print(f.encoding) print() # 파일 이름 print(f.name) print() # 모드 확인 print(f.mode) print() # 파일 내용 확인 cts = f.read() print(cts) pri.. 이전 1 다음