def mysql_to_dict(data, key):
 ret = {}
 headers = ['']
 for line in data:
  if (not line):
   continue
  if line.startswith('+'):
   continue
  comps = line.split('|')
  for comp in range(len(comps)):
   comps[comp] = comps[comp].strip()
  if (len(headers) > 1):
   index = (len(headers) - 1)
   row = {}
   for field in range(index):
    if (field < 1):
     continue
    else:
     row[headers[field]] = str_to_num(comps[field])
   ret[row[key]] = row
  else:
   headers = comps
 return ret

def mysql_to_dict ( data , key ) : ret = { } headers = [ '' ] for line in data : if ( not line ) : continue if line . startswith ( '+' ) : continue comps = line . split ( '|' ) for comp in range ( len ( comps ) ) : comps [ comp ] = comps [ comp ] . strip ( ) if ( len ( headers ) > 1 ) : index = ( len ( headers ) - 1 ) row = { } for field in range ( index ) : if ( field < 1 ) : continue else : row [ headers [ field ] ] = str_to_num ( comps [ field ] ) ret [ row [ key ] ] = row else : headers = comps return ret
convert mysql-style output to a python dictionary .