Python3 os.close () method
Python3 OS file / directory methods
Outline
os.close () method is used to close the specified file descriptor fd.
grammar
close () method syntax is as follows:
os.close(fd);
parameter
fd - file descriptor.
return value
This method has no return value.
Examples
The following example demonstrates the use of close () method:
#!/usr/bin/python3 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 above program output is:
关闭文件成功!!