小白教程
所有教程
关于
Search
172.69.58.16
172.69.58.16
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Os write”的源代码
本页内容
上一节:
Python3_os_path
下一节:
Python3_os_pardir
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os write}}[[Category:python3 os file methods|63]] = Python os.write() 方法 = [[os file methods|Python OS 文件/目录方法]] === 概述 === os.write() 方法用于写入字符串到文件描述符 fd 中. 返回实际写入的字符串长度。 在Unix中有效。 === 语法 === '''write()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.write(fd, str) </sample> === 参数 === * '''fd''' -- 文件描述符。 * '''str''' -- 写入的字符串。 === 返回值 === 该方法返回写入的实际位数。 == 以下实例演示了 write() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 fd = os.open("f1.txt",os.O_RDWR|os.O_CREAT) # 写入字符串 ret = os.write(fd,"This is xiaobai.wang site") # 输入返回值 print "写入的位数为: " print ret print "写入成功" # 关闭文件 os.close(fd) print "关闭文件成功!!" </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 写入的位数为: 23 写入成功 关闭文件成功!! </sample> [[os file methods|Python OS 文件/目录方法]]
返回至“
Os write
”。
上一节:
Python3_os_path
下一节:
Python3_os_pardir