Python OS File/Directory Methods\n\n* * *\n\n### Overview\n\nThe os.fsync() method forces the file with file descriptor fd to be written to the hard disk. On Unix, it calls the fsync() function; on Windows, it calls the _commit() function.\n\nIf you are going to manipulate a Python file object f, first f.flush(), then os.fsync(f.fileno()), to ensure that all memory associated with f is written to the hard disk. Valid on Unix and Windows.\n\nAvailable on Unix and Windows.\n\n### Syntax\n\nThe syntax format of the **fsync()** method is as follows:\n\nos.fsync(fd)\n\n### Parameters\n\n* **fd** -- File descriptor.\n\n### Return Value\n\nThis method has no return value.\n\n### Example\n\nThe following example demonstrates the use of the fsync() method:\n\n#!/usr/bin/python\n# -*- coding: UTF-8 -*-\n\nimport os, sys\n\n# Open file\nfd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )\n\n# Write string\nos.write(fd, "This is test")\n\n# Use fsync() method.\nos.fsync(fd)\n\n# Read content\nos.lseek(fd, 0, 0)\nstr = os.read(fd, 100)\nprint "Read string is : ", str\n\n# Close file\nos.close( fd)\n\nprint "Closed the file successfully!!"\n\nThe output of executing the above program is:\n\nRead string is : This is test\nClosed the file successfully!!\n\n
Python OS File/Directory Methods