Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.fdatasync() method

Python os.fdatasync() method

Python File methods Python OS file/directory methods


Overview

The os.fdatasync() method forces a file specified by the file descriptor fd to be written to disk, but does not force the file's status information to be updated. You can use this method if you need to flush the buffer.

Available on Unix.

Syntax

The **fdatasync()** method syntax is as follows:



os.fdatasync(fd);

Parameters

Return Value

This method has no return value.

Example

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



#!/usr/bin/python

# -*- coding: UTF-8 -*-



import os, sys



# Open file "/tmp/foo.txt"

fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )



# Write string

os.write(fd, "This is test")



# Using fdatasync() method

os.fdatasync(fd)



# Read file

os.lseek(fd, 0, 0)

str = os.read(fd, 100)

print "读取的字符是 : ", str



# Close file

os.close( fd )



print "关闭文件成功!!"

The output of the above program is:



读取的字符是 :  This is test

关闭文件成功!!

Python File methods Python OS file/directory methods