0

I have a configuration file that I would like to change settings to from a python script. Here is my skeleton code:

config = ConfigParser()        
config.read('settings.conf')
config.set("SCRIPT", "SOMEFIELD", "%s"%SOMEVALUE)
config.write(open("settings.conf","wb"))

This works fine, however it writes everything to one line. I might be being a bit picky, but would like to have new lines after each configurations field and section so that the file is human readable.

1 Answer 1

3

You are telling python to write a binary file ("b" char on 2nd arg of your open() call).

Use

config.write(open("settings.conf","w"))

Or better:

with open("settings.conf","w") as settings_file:
    config.write(settings_file)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.