Python3 os.close() Method
Python3 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:
Example
#!/usr/bin/python3
import
os
,
sys
Opening a File
fd
=
os
.
open
(
"foo.txt"
,
os
.
O_RDWR
|
os
.
O_CREAT
)
Write a string
os
.
write
(
fd
,
"This is test"
)
Closing a File
os
.
close
(
fd
)
(
"File closed successfully!!"
)
The output of the above program is:
关闭文件成功!!