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 writing of the file specified by the file descriptor `fd` to disk, but does not force the update of the file's status information. You can use this method if you need to flush buffers. 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 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 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!!" Executing the above program produces the following output: The read characters are : This is test File closed successfully!! [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Os FdatasyncOs Fchmod β†’