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()方法-的用法

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

来源:LearnFk无涯教程网

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

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

技术教程推荐

Java核心技术面试精讲 -〔杨晓峰〕

Java性能调优实战 -〔刘超〕

WebAssembly入门课 -〔于航〕

基于人因的用户体验设计课 -〔刘石〕

零基础入门Spark -〔吴磊〕

大厂设计进阶实战课 -〔小乔〕

Dubbo源码剖析与实战 -〔何辉〕

结构思考力 · 透过结构看思考 -〔李忠秋〕

AI 应用实战课 -〔黄佳〕

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