Latest web development tutorials

Python3 os.fdatasync () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.fdatasync () method is used to force the file is written to disk, the file specified by the file descriptor fd, but does not enforce the update file status information. If you need to refresh the buffer can use this method.

Available on Unix.

grammar

fdatasync () method syntax is as follows:

os.fdatasync(fd);

parameter

  • fd - file descriptor

return value

This method has no return value.

Examples

The following example demonstrates fdatasync () method of use:

#!/usr/bin/python3

import os, sys

# 打开文件 "/tmp/foo.txt"
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# 写入字符串
os.write(fd, "This is test")

# 使用 fdatasync() 方法
os.fdatasync(fd)

# 读取文件
os.lseek(fd, 0, 0)
str = os.read(fd, 100)
print ("读取的字符是 : ", str)

# 关闭文件
os.close( fd )

print ("关闭文件成功!!")

The above program output is:

读取的字符是 :  This is test
关闭文件成功!!

Python3 OS file / directory methods Python3 OS file / directory methods