无涯教程-OS File - os.close(fd)函数

59 阅读1分钟

Python方法close()关闭与文件描述符关联的fd。

os.close(fd) - 语法

os.close(fd);
  • fd    -  这是文件的文件描述符。

os.close(fd) - 示例

以下示例显示close()方法的用法。

#!/usr/bin/python

import os, sys

# Open a file fd=os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# Write one string os.write(fd, "This is test")

# Close opened file os.close( fd )

print "Closed the file successfully!!"

当无涯教程运行上面的程序时,它产生以下输出-

Closed the file successfully!!

参考链接

www.learnfk.com/python/os-c…