# Python 2.X only. In Python 3.X, inline comments are disabled # by default. Even then code is the same so if were enabled then # should fail in similar way. import sys from ConfigParser import ConfigParser from StringIO import StringIO content = """ [section] value1 = a;b value2 = a ; comment value3 = a; b ; comment """ input = StringIO(content) config = ConfigParser() config.readfp(input) config.write(sys.stdout) # This yields: # # [section] # value3 = a; b ; comment # value2 = a # value1 = a;b # # For value3 that first ';' doesn't have a space before it is # preventing the detection of the latter embedded comment where # a space does precede the ';'.