load_config(path) that parses lines of key=value into a dict. Skip blank lines and lines starting with #. Values keep everything after the first = (so url=http://x?a=1 works). Strip whitespace around both parts.load_config('app.cfg') # 'host = local\n# note\nurl=http://x?a=1\n'{'host': 'local', 'url': 'http://x?a=1'}Comment skipped; the second = survives inside the value.
line.split('=', 1) limits the split.
partition() is an equally clean option.