Python/기본문법
f.seek() (파이썬 파일 처리 함수)
yororing
2024. 8. 9. 17:03
00 개요
- 코드 분석 중 이 함수가 나와서 이에 대해 정리하고자 함
01 seek() 함수란
1. 정의 및 사용
- 파일을 다룰 때 사용됨
- 현재 파일 스트림 (file stream) 안에서의 파일 위치 (file position)를 설정 + 새로운 위치 반환
2. 문법
- f = file pointer 또는 file object
f.seek(offset[, from_what])
1) 매개변수
- offset (필수값):
- 현재 파일 스트림 안에서의 위치 (숫자값)
- 양수는 뒷쪽으로 (오른쪽), 음수는 앞쪽으로 (왼쪽) 이동
- from_what:
- the point of reference
- 기본값 = 0
- 종류:
- 0: sets the reference point at the beginning of the file
- 1: sets the reference point at the current file position
- 2: sets the reference point at the end of the file