How to write a .cfg file with ":" instead of "=" in python
Question:
I’m using python3 ConfigParser, my code is
conf = configparser.ConfigParser()
cfg_file = open('./config.cfg', 'w')
conf.set(None, 'a', '0')
conf.write(cfg_file)
cfg_file.close()
I expected the result to be a : 0
in the config.cfg file. However, I got a = 0
. Is there a way to replace "=" with ":"?
Answers:
Use the delimiters parameters to ConfigParser
:
When `delimiters’ is given, it will be used as the set of substrings
that divide keys from values.
conf = configparser.ConfigParser(delimiters=':')
Result:
[DEFAULT]
a : 0
I’m using python3 ConfigParser, my code is
conf = configparser.ConfigParser()
cfg_file = open('./config.cfg', 'w')
conf.set(None, 'a', '0')
conf.write(cfg_file)
cfg_file.close()
I expected the result to be a : 0
in the config.cfg file. However, I got a = 0
. Is there a way to replace "=" with ":"?
Use the delimiters parameters to ConfigParser
:
When `delimiters’ is given, it will be used as the set of substrings
that divide keys from values.
conf = configparser.ConfigParser(delimiters=':')
Result:
[DEFAULT]
a : 0