2

I have a .ini file which I want to modify a particular section. So for example,

[Section1]
Param1: Hello
Param2: World

[Section2]
fontsize = 10

[Section3]
integers = 971 508 1076 561

I want to modify the integers in section 3 and replace them with other integers. I have tried:

lis = "971 508 1076 561; 920 543 973 648 ; 831 492 936 544 ; 936 403 988 508"
config.set('sfr',lis)

But I'm getting errors; how can I fix this?

import configparser
config = configparser.ConfigParser()
config.read("C:\\Users\\Folder\\example.ini")
print(config.sections())
lis = "971 508 1076 561; 920 543 973 648 ; 831 492 936 544 ; 936 403 988 508"
config.set('sfr',lis)
2
  • Perhaps you could flesh out the code a little more as the snippet you have provided is of little use, ie. I to get errors with just those 2 lines in a python script. Commented Feb 17, 2017 at 19:58
  • Will that work? Commented Feb 17, 2017 at 20:01

1 Answer 1

4

You're missing the section and field to change the values of, try with:

config.set("Section3", "integers", lis)

Keep in mind that after changing the values you still need to save your config:

with open("C:\\Users\\Folder\\example.ini", "w") as f:
    config.write(f)
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.