Reputation: 97
I have a config file and it has an item as:
[time_format]
iso = "ISO (2015-12-31 13:30:55)"
I read the config file with configobj as:
config = ConfigObj(file_name);
section = config.keys();
After some reading, I write the config without modifying the above item as:
config.write();
The item in the config file becomes:
iso = ISO (2015-12-31 13:30:55)
The quotes disappear. Is there any way to keep the quotes?
Upvotes: 2
Views: 935
Reputation: 101
I had a similar problem and 'fixed' it by subclassing ConfigObj and overwriting the methods that remove and add the quotes -
from configobj import ConfigObj
class MyConfigObj(ConfigObj):
def __init__(self, *args, **kwargs):
ConfigObj.__init__(self, *args, **kwargs)
def _unquote(self, value):
return value
def _quote(self, value, multiline=True):
return value
Then use MyConfigObj in place of ConfigObj and config entries with quotation marks are read in and written back without change.
This works on the simple config files I have used, but I imagine on more complex config files (multiline entries, entries with lists etc.) further refinement will be needed!
Upvotes: 2