YouTip LogoYouTip

Os Fdatasync

# Python2.x Python os.fdatasync() Method [![Image 3: Python File Methods](#) Python 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, without forcing an update of the file's status information. You can use this method 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** -- file descriptor ### Return Value This method does not return a 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 a string os.write(fd, "This is test")# Use fdatasync() method os.fdatasync(fd)# Read file os.lseek(fd, 0, 0) str = os.read(fd, 100)print "The read characters are : ", str # Close file os.close( fd )print "File closed successfully!!" The output of the above program is: The read characters are : This is test File closed successfully!! [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Os FpathconfOs Fdatasync β†’