gpt4 book ai didi

python - 无法从python中的文件中读取数据

转载 作者:太空宇宙 更新时间:2023-11-04 10:22:51 25 4
gpt4 key购买 nike

我无法从 python 文件中读取数据。下面是我得到的示例代码和错误。

abc.txt has the value 2015-05-07

f = open("/opt/test/abc.txt","r")
f.read()
last_Exe_date = f.read()
f.close()

在读取文件 (anc.txt) 时出现错误:TypeError: argument 1 must be string or read-only character buffer, not file。我无法从文件 (abc.txt) 中将值读入 last_Exe_date。如果我的代码有误,你能纠正我吗?

最佳答案

当您读取一次文件时,光标位于文件的末尾,您将无法再重新读取它。通读the docs了解更多。并使用 readline 逐行读取文件。

哦,删除 read 调用末尾的分号...

关于python - 无法从python中的文件中读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31244805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com