Since the python 2.6 question is still unanswered, the following will work with python 2.7 or 2.6. This replaces the internal regular expression used to parse the option, delimiter, and value in ConfigParser.
def rawConfigParserAllowNoValue(config): '''This is a hack to support python 2.6. ConfigParser provides the option allow_no_value=True to do this, but python 2.6 doesn't have it. ''' OPTCRE_NV = re.compile( r'(?P<option>[^:=\s][^:=]*)'
Use as
fp = open("myFile.conf") config = ConfigParser.RawConfigParser() config = rawConfigParserAllowNoValue(config)
Side note
ConfigParser for Python 2.7 has OPTCRE_NV, but if we used it in the above function, the regular expression will return None for vi and value, which will cause ConfigParser to crash. Using the function above returns an empty string for vi and a value, and everyone is happy.
AaronS
source share