Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

How to delete ONLY the selected section from a file with config parser in Python?

$
0
0

I have a config file what looks like: config.cfg

[sectioname1]some:thing,some2:thing2,some3:thing3[sectioname2]some:thing,some2:thing2,some3:thing3

I tried to delete the first section with this def:

def deleteSection(section): path= 'config.cfg'    config.remove_section(section)    with open(path, "w") as config_file:        config.write(config_file)

How I try to call it in main:

if __name__=='__main__':if args.job=='delete':  delete(args.Section)

But right now it's delete everything in the file.


Viewing all articles
Browse latest Browse all 5049

Trending Articles