본문 바로가기

개발/Python

[Python] 파일 열기, 읽기

open('파일명입력', '모드 선택')

file = open('hello.txt', 'r')

모드

  • 'w'는 파일을 작성할 때
  • 'r'은 파일을 읽을 때

Methods

.read() : 내용을 하나의 문자열로 만들어 내보낸다

texts=file.read()​

 

Reference : https://www.boostcourse.org/cs122/ (모두를 위한 파이썬 7주차:파일 읽기)