Easy Tutorial
❮ Python Att List Reverse Python Check Element Exists In List ❯

Python3 os.close() Method

Python3 OS File/Directory Methods


Overview

The os.close() method is used to close the specified file descriptor fd.

Syntax

The syntax for the close() method is as follows:

os.close(fd);

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the close() method:

Example

#!/usr/bin/python3

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 ("File closed successfully!!")

Executing the above program outputs:

File closed successfully!!

Python3 OS File/Directory Methods

❮ Python Att List Reverse Python Check Element Exists In List ❯