28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Syntax

Following is the syntax for closerange() method:

os.closerange(fd_low, fd_high);

Parameters

• fd_low -- This is the Lowest file descriptor to be closed.

• fd_high -- This is the Highest file descriptor to be closed.

This function is equivalent to:

for fd in xrange(fd_low, fd_high):

try:

os.close(fd)

except OSError:

pass

Return Value

This method does not return any value.

Example

The following example shows the usage of closerange() 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 a single opened file

os.closerange( fd, fd)

print "Closed the file successfully!!"

This would create given file foo.txt and then write given content in that file.This will produce the following result:

Closed the file successfully!!

os.dup(fd)

Description

The method dup() returns a duplicate of file descriptor fd which can be used in place of original descriptor.

Syntax

Following is the syntax for dup() method:

os.dup(fd);

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!