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.dup() Method


previous next AddThis Social Bookmark Button


Description:

This method returns a duplicate of file descriptor fd which can be used in place of original descriptor.

Syntax:

os.dup(fd);

Parameters:

Here is the detail of parameters:

  • fd: This is the original file descriptor.

Example:

#!/usr/bin/python

import os, sys

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

# Get one duplicate file descriptor
d_fd = os.dup( fd )

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

# Close a single opened file
os.closerange( fd, d_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