OS File 中的 os.close(fd)函数

首页 / Python2入门教程 / OS File 中的 os.close(fd)函数

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!!"

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

链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-close.html

来源:LearnFk无涯教程网

Closed the file successfully!!

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

软件工程之美 -〔宝玉〕

DDD实战课 -〔欧创新〕

重学线性代数 -〔朱维刚〕

Linux内核技术实战课 -〔邵亚方〕

张汉东的Rust实战课 -〔张汉东〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

性能优化高手课 -〔尉刚强〕

搞定音频技术 -〔冯建元 〕

LangChain 实战课 -〔黄佳〕

好记忆不如烂笔头。留下您的足迹吧 :)