You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importsysfromStringIOimportStringIOfromconfigobjimportConfigObjc=ConfigObj(StringIO("""[Section1]"""))
d=ConfigObj(StringIO("""[Section1] # This is a Section2 comment [[Section2]] option2 = foo"""))
c.merge(d)
c.write(sys.stdout)
The output is:
[Section1]
[[Section2]]
option2 = foo
while I would have expected
[Section1]
# This is a Section2 comment
[[Section2]]
option2 = foo
The text was updated successfully, but these errors were encountered:
I should add that parentage is also not preserved on merge. This is what we do to get around these V5 limitations:
fromconfigobjimportSectiondefmerge_config(self_config, indict):
"""Merge and patch a config file"""# Do a ConfigObj merge:self_config.merge(indict)
# Then fix comments and parentage:patch_config(self_config, indict)
defpatch_config(self_config, indict):
"""The ConfigObj merge does not transfer over parentage, nor comments. This function fixes these limitations. """forkeyinself_config:
ifisinstance(self_config[key], Section) \
andkeyinindictandisinstance(indict[key], Section):
self_config[key].parent=self_configself_config[key].main=self_config.mainself_config.comments[key] =indict.comments[key]
self_config.inline_comments[key] =indict.inline_comments[key]
patch_config(self_config[key], indict[key])
Using ConfigObj v5.0.6, consider this:
The output is:
while I would have expected
The text was updated successfully, but these errors were encountered: