28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

os.chroot("/tmp/usr")

print "Changed root path successfully!!"

Let us compile and run the above program, this will produce the following result:

Changed root path successfully!!

os.close(fd)

Description

The 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!!"

Let us compile and run the above program, this will produce the following result:

Closed the file successfully!!

os.closerange(fd_low, fd_high)

Description

The method closerange() closes all file descriptors from fd_low (inclusive) to fd_high (exclusive), ignoring

errors.This method is introduced in Python version 2.6.

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!