Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python os.closerange() Method


previous next AddThis Social Bookmark Button


Description:

This method closes all file descriptors from fd_low (inclusive) to fd_high (exclusive), ignoring errors.

This method is introduced in Python version 2.6.

Syntax:

os.closerange(fd_low, fd_high);

Parameters:

Here is the detail of parameters:

  • fd_low: Lowest file descriptor to be closed.

  • fd_high: 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

Example:

#!/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 all the files successfully!!"

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

Closed all the files successfully!!


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names