Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 os.close() Method

Python3 os.close() Method

Python3 OS File/Directory Methods 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

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

)

print

(

"File closed successfully!!"

)

The output of the above program is:

关闭文件成功!!

Python3 OS File/Directory Methods Python3 OS File/Directory Methods