Python open().read()

사용 버전 : Python 3.6.8


사용 프로그램 : Atom 1.34.0 x64





파이썬 open().read()에 대해서 알아보겠습니다.



open() 괄호에는 파일을 열 경로를, read() 괄호에는 읽을 데이터양을 적습니다.





open().read()는 파일을 열고, str 형식으로 읽습니다.


"shakespeare.txt" 내용입니다.

























이번에는 read에 읽을 데이터양을 설정한 뒤 실행해 보겠습니다.







다음과 같이 정해진 길이만큼만 읽어들였습니다.







읽은 파일은 리스트가 아닌, 하나의 문자열로 취급됩니다.










끝.




카테고리: Standard Library, Python

댓글

이 블로그의 인기 게시물

Python urllib.parse.quote()

Forensics .pyc 파일 .py로 복구하기

KiCad 시작하기 7 (FreeRoute 사용하기 2)

음악 총보(Score), 파트보(Part)

KiCad 시작하기 3 (새로운 소자 추가하기)

Kivy 시작하기 12 (Pyinstaller로 exe 파일 만들기)

딩기 요트 명칭

Android App architecture: State holders and UI state

Android Default background color setting

Android Compose automation for getting localized images to use on Play Store app image