Python3 os.dup2() 方法
Python 3 教程
· 2019-02-07 09:26:29
概述
os.dup2() 方法用于将一个文件描述符 fd 复制到另一个 fd2。
Unix, Windows 上可用。
语法
dup2()方法语法格式如下:
os.dup2(fd, fd2);
参数
fd -- 要被复制的文件描述符
fd2 -- 复制的文件描述符
返回值
没有返回值。
实例
以下实例演示了 dup2() 方法的使用:
实例
import os
# 打开一个文件
f=open('txt','a')
# 将这个文件描述符代表的文件,传递给 1 描述符指向的文件(也就是 stdout)
os.dup2(f.fileno(), 1)
# 关闭文件
f.close()
# print 输出到标准输出流,就是文件描述符1
print('codercto')
print('google')
执行以上程序输出结果为, 生成一个txt文件,内容是::
codercto google
点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html
The Haskell School of Expression
Paul Hudak / Cambridge University Press / 2000-01 / USD 95.00
Functional programming is a style of programming that emphasizes the use of functions (in contrast to object-oriented programming, which emphasizes the use of objects). It has become popular in recen......一起来看看 《The Haskell School of Expression》 这本书的介绍吧!
CSS 压缩/解压工具
在线压缩/解压 CSS 代码
Markdown 在线编辑器
Markdown 在线编辑器