Get your
own Python
server
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
#Import os Library import os # open file fd = os.open("test.txt", os.O_RDWR) #Print original size of file (in bytes) print("File size (in bytes):", os.stat(fd).st_size) length = 10 #Truncate file to 10 bytes os.ftruncate(fd, length) #Print new size of file (in bytes) print("File size (in bytes):", os.stat(fd).st_size) #close file os.close(fd)
File size (in bytes): 36
File size (in bytes): 10