os.ftruncate(fd, length)
fd -- 这是需要被截断的文件描述符
length -- 这是需要被截断的文件的长度
#!/usr/bin/python3 import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # Write one string os.write(fd, "This is test - This is test") # Now you can use ftruncate() method. os.ftruncate(fd, 10) # Now read this file from the beginning. os.lseek(fd, 0, 0) str = os.read(fd, 100) print ("Read String is : ", str) # Close opened file os.close( fd ) print ("Closed the file successfully!!")
Read String is : This is te Closed the file successfully!!
在线咨询
免费热线
资料发放
技术答疑
关注微信