Os Close
# Python2.x Python os.close() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.close() method is used to close the specified file descriptor fd.
### Syntax
The syntax format of the **close()** method is as follows:
os.close(fd);
### Parameters
* **fd** -- File descriptor.
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the close() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Open file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Write string os.write(fd, "This is test")# Close file os.close( fd )print "File closed successfully!!"
The output of executing the above program is:
File closed successfully!!
[![Image 4: Python File Methods
YouTip