2024-09-27 23:19:42 发布
网友
我必须从一个文件中读一行,做一些计算,然后写入另一个文件。 我做过这样的事
fd= open("abc.txt","w") for line in open("test.txt","r"): Do something Here fd.write(modifiedline)
我通常用open和for open进行逐行操作。 上面的方法是我用ok来使用的,还是有更好的方法来表示open和with open一起使用。在
我是一名学生,希望了解更多。感谢任何帮助。在
编码
with open("abc.txt", 'w') as outfi,open("test.txt","r") as infil: for line in infil: Do something Here outfi.write(modifiedline)
编码
相关问题 更多 >
编程相关推荐