Easy Tutorial
❮ Ref Math Log1P Python Os Lstat ❯

Python3 os.fdatasync() Method

Python3 OS File/Directory Methods


Overview

The os.fdatasync() method is used to force the file to be written to disk, specified by the file descriptor fd, but it does not enforce the update of the file's status information. This method can be used if you need to flush the buffer.

Available on Unix.

Syntax

The syntax for the fdatasync() method is as follows:

os.fdatasync(fd);

Parameters

-

fd -- The file descriptor

Return Value

This method does not return any value.

Example

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

#!/usr/bin/python3

import os, sys

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

# Write a string
os.write(fd, "This is test")

# Use the fdatasync() method
os.fdatasync(fd)

# Read the file
os.lseek(fd, 0, 0)
str = os.read(fd, 100)
print("The read string is : ", str)

# Close the file
os.close(fd)

print("Successfully closed the file!!")

Executing the above program outputs:

The read string is :  This is test
Successfully closed the file!!

Python3 OS File/Directory Methods

❮ Ref Math Log1P Python Os Lstat ❯