相关疑难解决方法(0)

将行前置到文件的开头

我可以使用单独的文件来完成此操作,但如何在文件的开头添加一行?

f=open('log.txt','a')
f.seek(0) #get to the first position
f.write("text")
f.close()
Run Code Online (Sandbox Code Playgroud)

由于文件以追加模式打开,因此从文件末尾开始写入.

python

60
推荐指数
6
解决办法
9万
查看次数

标签 统计

python ×1