YouTip LogoYouTip

Os Dup

# Python2.x Python os.dup() Method [![Image 3: Python File Methods](#) Python OS File/Directory Methods](#) * * * ### Overview The os.dup() method is used to duplicate the file descriptor fd. ### Syntax The syntax for the **dup()** method is as follows: os.dup(fd); ### Parameters * **fd** -- file descriptor ### Return Value Returns the duplicated file descriptor. ### Example The following example demonstrates the use of the dup() method: #!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Open file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Duplicate file descriptor d_fd = os.dup( fd )# Write to file using duplicated file descriptor os.write(d_fd, "This is test")# Close files os.closerange( fd, d_fd)print "All files closed successfully!!" Executing the above program produces the following output: All files closed successfully!! [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Rust FunctionRust Data Types β†’