这篇教程Python os.open() 方法写得很实用,希望能帮到您。 概述os.open() 方法用于打开一个文件,并且设置需要的打开选项,模式参数mode参数是可选的,默认为 0777。 语法open()方法语法格式如下: os.open(file, flags[, mode]); 参数返回值返回新打开文件的描述符。 实例以下实例演示了 open() 方法的使用: #!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys# 打开文件fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# 写入字符串os.write(fd, "This is test")# 关闭文件os.close( fd )print "关闭文件成功!!" 执行以上程序输出结果为: 关闭文件成功!! Python os.mknod() 方法 Python os.openpty() 方法 |