def read_keyval(path):
 if os.path.isdir(path):
  path = os.path.join(path, 'keyval')
 keyval = {}
 if os.path.exists(path):
  for line in open(path):
   line = re.sub('#.*', '', line).rstrip()
   if (not re.search('^[-\\.\\w]+=', line)):
    raise ValueError(('Invalid format line: %s' % line))
   (key, value) = line.split('=', 1)
   if re.search('^\\d+$', value):
    value = int(value)
   elif re.search('^(\\d+\\.)?\\d+$', value):
    value = float(value)
   keyval[key] = value
 return keyval

def read_keyval ( path ) : if os . path . isdir ( path ) : path = os . path . join ( path , 'keyval' ) keyval = { } if os . path . exists ( path ) : for line in open ( path ) : line = re . sub ( '#.*' , '' , line ) . rstrip ( ) if ( not re . search ( '^[-\\.\\w]+=' , line ) ) : raise ValueError ( ( 'Invalid format line: %s' % line ) ) ( key , value ) = line . split ( '=' , 1 ) if re . search ( '^\\d+$' , value ) : value = int ( value ) elif re . search ( '^(\\d+\\.)?\\d+$' , value ) : value = float ( value ) keyval [ key ] = value return keyval
read a key-value pair format file into a dictionary .