Python os.close() method
Python OS file/directory methods
Overview
The os.close() method closes the specified file descriptor fd.
Syntax
The **close()** method syntax is as follows:
os.close(fd);
Parameters
-
fd -- The file descriptor.
Return Value
This method has no return value.
Example
The following example shows how to use 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 "关闭文件成功!!"
The output of the above program is:
关闭文件成功!!