#Python3 os.write() 方法
#用于写入字符串到文件描述符 fd 中. 返回实际写入的字符串长度。在Unix中有效。
====================
#!/usr/bin/python3
import os, sys
# 打开文件
fd = os.open("foo.txt",os.O_RDWR|os.O_CREAT)
# 写入字符串
str = "This is runoob.com site"
ret = os.write(fd,bytes(str, 'UTF-8'))
# 输入返回值
print ("写入的位数为: ")
print (ret)
print ("写入成功")
# 关闭文件
os.close(fd)
print ("关闭文件成功!!") |