Python-os-dup
提供:Dev Guides
Python os.dup()メソッド
説明
Pythonメソッド* dup()*は、元の記述子の代わりに使用できるファイル記述子_fd_の複製を返します。
構文
以下は* dup()*メソッドの構文です-
os.dup(fd);
パラメーター
- fd -これは元のファイル記述子です。
戻り値
このメソッドは、ファイル記述子の複製を返します。
例
次の例は、dup()メソッドの使用方法を示しています-
#!/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!!"
上記のプログラムを実行すると、次の結果が生成されます-
Closed all the files successfully!!