Python_28_ open(파일생성)

hyeong taek jo·2023년 9월 13일

Python

목록 보기
31/53

📌 open(파일 생성)

  • 파일 생성(파일 쓰기)
  • test.txt 파일 생성함
file = open('test.txt', 'w')    #쓰기 모드로 열기
file.write('hello')             #text.txt파엘에 hello 쓰기
file.close()

📌 open(파일 읽기모드)

  • 파일 읽기
  • test.txt 파일을 읽기 모드로 열고, 내용을 출력

영어 읽기 모드

file = open('test.txt','r')
str = file.read()
print(str)
file.close()

한글 읽기 모드

file = open('test3.txt','r',encoding='utf-8')
str = file.read()
print(str)
file.close()
profile
마포구 주민

0개의 댓글