← 返回列表

Python3 os 模块 lseek 方法

Python3 os 模块 lseek 方法 #!/usr/bin/python3 import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # Write one string line = "This is test" b = line.encode() os.write(fd, b) # Now you can use fsync() method. # Infact here you would not be able to see its effect. os.fsync(fd) # Now read this file from the beginning os.lseek(fd, 0, 0) line = os.read(fd, 100) print ("Read String is : ", line.decode()) # Close opened file os.close( fd ) print ("Closed the file successfully!!")

Python3 os 模块 lseek 方法

#!/usr/bin/python3
import os, sys

# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# Write one string
line = "This is test"
b = line.encode()
os.write(fd, b)

# Now you can use fsync() method.
# Infact here you would not be able to see its effect.
os.fsync(fd)

# Now read this file from the beginning
os.lseek(fd, 0, 0)
line = os.read(fd, 100)
print ("Read String is : ", line.decode())

# Close opened file
os.close( fd )

print ("Closed the file successfully!!")

打开资源 ↗

交流与评论