파이썬 파일입출력

John Jeong (토론 | 기여)님의 2016년 7월 22일 (금) 20:39 판 (→‎파일 열기)

1 개념

python files
  • 파이썬으로 파일 내용의 읽고 쓰기가 가능

2 파일 열기

  • open("파일이름", "모드")

열기 모드

모드 설명
r 읽기 모드
w 쓰기 모드
a 추가 모드
b 바이너리 모드

3 예시

open.py 파일이 hello.txt 파일을 열어 그 내용을 출력
  • open.py
file = open('./hello.txt')
content = file.read()
print(content)
*hello.txt
<source lang="python">
file = open('./hello.txt')
content = file.read()
print(content)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}