我可以使用单独的文件来完成此操作,但如何在文件的开头添加一行?
f=open('log.txt','a') f.seek(0) #get to the first position f.write("text") f.close()
由于文件以追加模式打开,因此从文件末尾开始写入.
python
python ×1