I am trying to read .ini
file with keywords having single items or list items. When I try to print single item strings and float values, it prints as h,e,l,l,o
and 2, ., 1
respectively, whereas it should have been just hello
and 2.1
. Also, when I try to write new single item string/float/integer, there is ,
at the end. I am new to python and dealing with configobj
. Any help is appreciated and if this question has been answered previously, please direct me to it. Thanks!
from configobj import ConfigObj
Read
config = ConfigObj('para_file.ini')
para = config['Parameters']
print(", ".join(para['name']))
print(", ".join(para['type']))
print(", ".join(para['value']))
Write
new_names = 'hello1'
para['name'] = [x.strip(' ') for x in new_names.split(",")]
new_types = '3.1'
para['type'] = [x.strip(' ') for x in new_types.split(",")]
new_values = '4'
para['value'] = [x.strip(' ') for x in new_values.split(",")]
config.write()
My para_file.ini
looks like this,
[Parameters]
name = hello1
type = 2.1
value = 2