Python3 os.fdatasync() Method

Python3 OS 文件/目录方法Python3 OS File/Directory Methods


Overview

The os.fdatasync() method is used to force the file specified by the file descriptor fd to be written to disk, but it does not force updating the file's status information. If you need to flush the buffer, you can use this method.

Available on Unix.

Syntax

fdatasync()The method syntax is as follows:

os.fdatasync(fd);

Parameters

  • fd-- File descriptor

Return Value

This method has no return value.

Example

The following example demonstrates the usage of the fdatasync() method:

#!/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 output of the above program is:

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

Python3 OS 文件/目录方法Python3 OS File/Directory Methods

Other Extensions