python中的write字体⼤⼩_Pythonos.write()⽅法Python os.write() ⽅法
概述
os.write() ⽅法⽤于写⼊字符串到⽂件描述符 fd 中. 返回实际写⼊的字符串长度。
在Unix中有效。
语法
write()⽅法语法格式如下:
os.write(fd, str)
参数
fd -- ⽂件描述符。
str -- 写⼊的字符串。
write的返回值返回值
该⽅法返回写⼊的实际位数。
实例
以下实例演⽰了 write() ⽅法的使⽤:
#!/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 runoob site")
# 输⼊返回值
print "写⼊的位数为: "
print ret
print "写⼊成功"
# 关闭⽂件
os.close(fd)
print "关闭⽂件成功!!"
执⾏以上程序输出结果为:
写⼊的位数为:
23
写⼊成功
关闭⽂件成功!!