"파이썬 파일입출력"의 두 판 사이의 차이

25번째 줄: 25번째 줄:
content = file.read()
content = file.read()
print(content)
print(content)
</source>
*hello.txt
*hello.txt
<source lang="python">
<source lang="python">
30번째 줄: 31번째 줄:
content = file.read()
content = file.read()
print(content)
print(content)
</source>
</source>


[[분류: python]]
[[분류: python]]

2016년 7월 22일 (금) 20:40 판

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
file = open('./hello.txt')
content = file.read()
print(content)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}