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

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

Python方法fdatasync()强制将具有filedescriptorfd的文件写入磁盘。这不强制更新元数据。如果你想刷新你的缓冲区,那么你可以使用这个方法。

os.fdatasync(fd) - 语法

os.fdatasync(fd);
  • fd  -  这是要为其写入数据的文件描述符。

os.fdatasync(fd) - 示例

以下示例显示了fdatasync()方法-的用法

#!/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")

# Now you can use fdatasync() method.
# Infact here you would not be able to see its effect.
os.fdatasync(fd)

# Now read this file from the beginning.
os.lseek(fd, 0, 0)
str=os.read(fd, 100)
print "Read String is : ", str

# Close opened file
os.close( fd )

print "Closed the file successfully!!"

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

Read String is :  This is test
Closed the file successfully!!

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

技术教程推荐

朱赟的技术管理课 -〔朱赟〕

从0开始学大数据 -〔李智慧〕

Flutter核心技术与实战 -〔陈航〕

小马哥讲Spring核心编程思想 -〔小马哥〕

大厂晋升指南 -〔李运华〕

说透低代码 -〔陈旭〕

超级访谈:对话毕玄 -〔毕玄〕

AI绘画核心技术与实战 -〔南柯〕

结构沟通力 -〔李忠秋〕

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