Python os.close() Method
Python OS File/Directory Methods
Overview
The os.close() method is used to close the specified file descriptor fd.
Syntax
close()The method syntax is as follows:
os.close(fd);
Parameters
fd-- file descriptor.
Return Value
This method has no return value.
Example
The following example demonstrates the use of the close() method:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 写入字符串 os.write(fd, "This is test") # 关闭文件 os.close( fd ) print "关闭文件成功!!"
The output of the above program is:
File closed successfully!!Other Extensions