如何使用python在新行中写入文件?

2024-06-14 09:24:57 发布

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

我正在尝试创建一个脚本,将新的别名写入bashrc,但是当我运行scrip时,它会写入第一行或最后一行

with open ("/user/.bashrc","a+") as f1:
   f1.write(new_alias + " " + alias_command)
   f1.seek(0,0)               # This writes in the first line and (1,0) writes in the last
   command = f1.read()
   print command              # To show me the input without getting into the file every time

所以我想让它在输入新别名时创建一个新行,这样它就不会把所有内容都弄脏,并产生不必要的错误


Tags: thein脚本newaswithaliasopen