Python 파일 truncate() 메서드
예시
추가를 위해 "a"가 있는 파일을 연 다음 파일을 20바이트로 자릅니다.
f = open("demofile2.txt", "a")
f.truncate(20)
f.close()
#open
and read the file after the truncate:
f = open("demofile2.txt", "r")
print(f.read())
정의 및 사용
이 truncate()
메서드는 파일의 크기를 지정된 바이트 수로 조정합니다.
크기를 지정하지 않으면 현재 위치가 사용됩니다.
통사론
file.truncate(size)
매개변수 값
Parameter | Description |
---|---|
size | Optional. The size of the file (in bytes) after the truncate. Default None, which means the current file stream position. |