gpt4 book ai didi

python - 尝试在 2 个文件之间切换文本

转载 作者:太空宇宙 更新时间:2023-11-04 03:43:07 24 4
gpt4 key购买 nike

from sys import argv

script, f1, f2 = argv

print """This program is going to switch the
content of the two files you just selected."""

first_file = open(f1, 'r+')
first_content = first_file.read()


second_file = open(f2, 'r+')
second_content = second_file.read()


final_first = first_file.write(second_content)
final_second = second_file.write(first_content)

IOError: [Errno 0] 错误


我正在尝试同时在两个文本文件之间切换内容。想法?

最佳答案

您已到达 EOF(文件末尾)。

在写入之前尝试调用 first_file.seek(0,0)second_file.seek(0, 0)

有更简单的方法来交换文件内容,例如通过重命名文件

关于python - 尝试在 2 个文件之间切换文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25355159/

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