읽기든 쓰기든 파이썬 파일은 파이썬 문자열(즉, 유니코드)을 다루기 위한 텍스트 모드를 기본
으로 한다. 이는 파일 모드에
b
를 추가해서 열 수 있는 이진 모드와는 다르다.
UTF
-
8
인코딩
을 사용하는 비
-
아스키 문자가 포함된 파일을 살펴보자.
In
[
230
]:
with open
(
path
)
as f
:
.....:
chars
=
f
.
read
(
10
)
In
[
231
]:
chars
Out
[
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.