与文件一起打开

2024-09-27 23:19:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须从一个文件中读一行,做一些计算,然后写入另一个文件。 我做过这样的事

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一起使用。在

我是一名学生,希望了解更多。感谢任何帮助。在


Tags: 文件方法intesttxtforhereline

热门问题