YouTip LogoYouTip

Python3 Os Fsync

# Python3.x Python3 os.fsync() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The os.fsync() method forces the file with file descriptor fd to be written to disk. On Unix, it calls the fsync() function; on Windows, it calls the _commit() function. If you are operating on a Python file object f, first call f.flush(), then os.fsync(f.fileno()) to ensure all memory associated with f is written to disk. It is effective on Unix and Windows. Available on Unix and Windows. ### Syntax The syntax for the **fsync()** method is as follows: os.fsync(fd) ### Parameters * **fd** -- The file descriptor. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the fsync() method: #!/usr/bin/python3import os, sys # Open the file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Write a string os.write(fd, "This is test")# Use the fsync() method. os.fsync(fd)# Read the content os.lseek(fd, 0, 0) str = os.read(fd, 100)print ("The read string is : ", str)# Close the file os.close( fd)print ("File closed successfully!!") The output of executing the above program is: The read string is : This is test File closed successfully!! [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) [](#)(#) (#)[](#)
← Python3 Os FsyncPython3 Os Fstat β†’