0
votes

How can I update config file with libconfig ? I want to update without removing other content of file

https://pypi.python.org/pypi/libconf

for example

RTL_test: {
  My_model : {
     tests = ["test1","test2","test3","test4"];
     ignore = ["test2"];
};
};

cfg['RTL_test']['My_model']['ignore']='' 
1

1 Answers

0
votes

With libconf.dump(cfg, f):

import libconf

# read
with open('example.cfg') as f:
  config = libconf.load(f)

config['RTL_test']['My_model']['ignore'] = 'updated'

# write
with open('example.cfg', 'w') as f:
  libconf.dump(config, f)      

Other contents like comments get lost by design and it's not possible to preserve them without modifying the source of the libconf package. You may want to look for another package or solutions like writing your own serializer/deserializer.