ConfigParser 覆盖配置文件的内容

ConfigParser overwriting the content of config file

我在写入配置文件时遇到问题。我有两个 Python 脚本读取和写入同一个文件。问题是当我从一个脚本写入它时它覆盖了另一个脚本的内容。

这是我的代码:

authfile = "Users/.ahs" # .ahs is a hidden file
config = ConfigParser.ConfigParser()
tmpfile = open(authfile, "w+")
config.add_section(s)
config.set(s, k, t)
config.write(tmpfile)
tmpfile.close()

w+ 打开文件时截断文件,你确定你不是指 aa+ 吗?

Confused by python file mode "w+"