小白教程
所有教程
关于
Search
172.69.7.53
172.69.7.53
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os popen”的源代码
本页内容
上一节:
Python3_os_pipe
下一节:
Python3_os_read
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.popen(command[, mode[, bufsize]])}}[[Category:python3 os file methods|42]] = Python3 os.popen() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.popen() 方法用于从一个命令打开一个管道。 在Unix,Windows中有效 === 语法 === '''popen()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.popen(command[, mode[, bufsize]]) </sample> === 参数 === * '''command''' -- 使用的命令。 * '''mode''' -- 模式权限可以是 'r'(默认) 或 'w'。 * '''bufsize''' -- 指明了文件需要的缓冲大小:0意味着无缓冲;1意味着行缓冲;其它正值表示使用参数大小的缓冲(大概值,以字节为单位)。负的bufsize意味着使用系统的默认值,一般来说,对于tty设备,它是行缓冲;对于其它文件,它是全缓冲。如果没有改参数,使用系统的默认值。 === 返回值 === 返回一个文件描述符号为fd的打开的文件对象 == 以下实例演示了 popen() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 使用 mkdir 命令 a = 'mkdir nwdir' b = os.popen(a,'r',1) print (b) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> open file 'mkdir nwdir', mode 'r' at 0x81614d0 </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os popen
”。
上一节:
Python3_os_pipe
下一节:
Python3_os_read