file objects
-
File ObjectsPython 2020. 8. 22. 13:52
with open('path_to_file', 'r') as f: # Do something with f 위 사용법 이외의 사용법외의 다른 유용한 method, attribute를 찾아봤다 1-1. 파일 내용 가져오기: read() with open('test.txt', 'r') as f: f_contents = f.read() print(f_contents) 1-2. 글자수만큼 가져오기: read(num_characters) with open('test.txt', 'r') as f: size_to_read = 10 f_contents = f.read(size_to_read) print(f_contents) 1-3. 파일 시작 지점으로 돌아오기: seek(0) with open('test.txt', 'r..