I have config file,
[local]
variable1 : val1 ;#comment1
variable2 : val2 ;#comment2
code like this reads only value of the key:
class Config(object):
def __init__(self):
self.config = ConfigParser.ConfigParser()
self.config.read('config.py')
def get_path(self):
return self.config.get('local', 'variable1')
if __name__ == '__main__':
c = Config()
print c.get_path()
but i also want to read the comment present along with the value, any suggestions in this regards will be very helpful.
Your only solutions is to write another
ConfigParseroverriding the method_read(). In yourConfigParseryou should delete all checks about comment removal. This is a dangerous solution, but should work.In the
ValuesWithCommentsConfigParserI fixed some imports and deleted the appropriate sections of code.Using the same
config.inifrom my previous answer, I can prove the previous code is correct.