logo

Python Os.close() Method


Show

Description

Python method close() closes the associated with file descriptor fd.

Syntax

Following is the syntax for close() method:

os.close(fd);

Parameters

  • fd − This is the file descriptor of the file.

Return Value

This method does not return any value.

Example

The following example shows the usage of close() method.

#!/usr/bin/python

import os, sys

# Open a file
fd = os.open( "foo.txt", os.O_RDWR'os.O_CREAT )

# Write one string
os.write(fd, "This is test")

# Close opened file
os.close( fd )

print "Closed the file successfully!!"

When we run the above program, it produces the following result:

Closed the file successfully!!

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.