首页 > 编程知识 正文

python中predict函数,python defaultdict函数

时间:2023-05-04 09:48:53 阅读:171186 作者:4819

Python的os.fsync (方法返回将文件描述符fd强制写入磁盘。 如果要使用Python文件对象f,请首先运行f.flush (然后运行OS.fsync ) f.fileno ) ),以确保与f关联的所有内部缓冲区都将写入磁盘。

语法

fsync ) )方法的语法如下所示-

这是OS.fsync (软盘)

参数

软盘这是缓冲区同步的文件描述符(必填)。

返回值

此方法没有返回值。

样品

以下示例说明如何使用fsync ) )方法。

#! /usr/土豪烧鹅/python3

import os,sys

# Open a file

FD=OS.open(foo.txt ),os.O_RDWR|os.O_CREAT ) ) ) ) ) ) ) ) ) )。

# Write one string

line='this is test '

b=line.encode (

OS.write(FD,b ) )。

# Now you can use fsync () method。

# infacthereyouwouldnotbeabletoseeitseffect。

这是OS.fsync (软盘)

# nowreadthisfilefromthebeginning

OS.lseek(FD,0,0 ) )。

line=OS.read(FD,100 ) )。

b=line.decode (

打印(readstring is :b ) ) ) ) ) ) ) ) )。

# Close opened file

这是OS.close (软盘)

打印(closedthefilesuccessfully! ' )

执行上述代码将产生以下结果-

Read String is : this is test

闭上the file successfully!

我给你奖励

纠错/补充

藏品

添加QQ群、易百教程官方技术学习群

注意:建议各位候选人按照自己的技术方向添加小组。 建议在同一QQ上最多添加三个组。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。