简体   繁体   中英

ConfigParser overwriting the content of config file

I am having a problem when writing to a config file. I have two Python scripts that read and write to the same file. the problem is when I write to it from one script it overwrites the content from the other script.

Here is my code:

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+ truncates the file when it opens, are you sure you didn't mean a or a+ ?

See Confused by python file mode "w+"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM