Python方法dup()返回文件描述符fd的副本,可用于代替原始描述符。
os.dup(fd);
fd - 这是原始文件描述符。
此方法返回文件描述符的副本。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-dup.html
来源:LearnFk无涯教程网
以下示例显示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!!
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)