I have the following code, where the filePath
is the path to a cfg file on disk. When I parse it, it also reads the inline comments (the ones with space + ";"
).
Some lines of the result:
xlsx:Yes ; comment goes here
html:Yes ; comment goes here
It should be:
xlsx:Yes
html:Yes
def ParseFile(filePath):
"""this function returns the parsed CFG file"""
parser = configparser.ConfigParser()
print("Reading config file from %s" % filePath)
parser.read(filePath)
for section in parser.sections():
print("[ SECTION: %s ]" % section)
for option in parser.options(section):
print("%s:%s" % (option, parser.get(section, option)))