You are here : python_2ososdup

os.dup() - os

             

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


  • fd -- This is the original file descriptor.


Syntax


os.dup(fd);


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


Output / Return Value

When we run above program, it produces following result:


Closed all the files successfully!!


Limitations


Alternatives / See Also


Reference