小白教程
所有教程
关于
Search
172.71.254.144
172.71.254.144
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os read”的源代码
本页内容
上一节:
Python3_os_popen
下一节:
Python3_os_readlink
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.read(fd, n)}}[[Category:python3 os file methods|43]] = Python3 os.read() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.read() 方法用于从文件描述符 fd 中读取最多 n 个字节,返回包含读取字节的字符串,文件描述符 fd对应文件已达到结尾, 返回一个空字符串。 在Unix,Windows中有效 === 语法 === '''read()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.read(fd,n) </sample> === 参数 === * '''fd''' -- 文件描述符。 * '''n''' -- 读取的字节。 === 返回值 === 返回包含读取字节的字符串 == 以下实例演示了 read() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 打开文件 fd = os.open("f1.txt",os.O_RDWR) # 读取文本 ret = os.read(fd,12) print (ret) # 关闭文件 os.close(fd) print ("关闭文件成功!!") </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> This is test 关闭文件成功!! </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os read
”。
上一节:
Python3_os_popen
下一节:
Python3_os_readlink