写入后,关闭前从文件读取

写入后,关闭前从文件读取,第1张

写入后,关闭前从文件读取

您需要使用以下命令将文件对象的索引重置为第一个位置

seek()

with open("outfile1.txt", 'r+') as f:    f.write("foobar")    f.flush()    # "reset" fd to the beginning of the file    f.seek(0)    print("File contents:", f.read())

这将使文件可供读取



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5674686.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存