def text_to_dict(text):
 res = {}
 if (not text):
  return res
 for line in text.splitlines():
  line = line.strip()
  if (line and (not line.startswith('#'))):
   (key, value) = [w.strip() for w in line.split('=', 1)]
   if (key in res):
    try:
     res[key].append(value)
    except AttributeError:
     res[key] = [res[key], value]
   else:
    res[key] = value
 return res

def text_to_dict ( text ) : res = { } if ( not text ) : return res for line in text . splitlines ( ) : line = line . strip ( ) if ( line and ( not line . startswith ( '#' ) ) ) : ( key , value ) = [ w . strip ( ) for w in line . split ( '=' , 1 ) ] if ( key in res ) : try : res [ key ] . append ( value ) except AttributeError : res [ key ] = [ res [ key ] , value ] else : res [ key ] = value return res
parse multilines text containing simple key=value lines and return a dict of {key: value} .