Python3 os.lseek () method
Python3 OS file / directory methods
Outline
os.lseek () method is used to set the current position of file descriptor fd to pos, how modify.
In Unix, Windows effectively.
grammar
lseek () method syntax is as follows:
os.lseek(fd, pos, how)
parameter
fd - file descriptor.
pos - which is given with respect to the parameters of how the location in the document..
how - document reference position.pos SEEK_SET 0 Setup from the File or the beginning of the calculation; SEEK_CUR or 1 from the current position calculation; os.SEEK_END or two from the end of the file begins.
return value
This method has no return value.
Examples
The following example demonstrates lseek () method of use:
#!/usr/bin/python3 import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 写入字符串 os.write(fd, "This is test") # 所有 fsync() 方法 os.fsync(fd) # 从开始位置读取字符串 os.lseek(fd, 0, 0) str = os.read(fd, 100) print ("Read String is : ", str) # 关闭文件 os.close( fd ) print ("关闭文件成功!!")
The above program output is:
关闭文件成功!!