def guess_format(filename):
 last_period = filename.rfind('.')
 if (last_period == (-1)):
  return 'fixed'
 extension = filename[(last_period + 1):].lower()
 if (extension in ('csv', 'dbf', 'fixed', 'xls', 'xlsx')):
  return extension
 elif (extension in ['json', 'js']):
  return 'json'
 return None

def guess_format ( filename ) : last_period = filename . rfind ( '.' ) if ( last_period == ( - 1 ) ) : return 'fixed' extension = filename [ ( last_period + 1 ) : ] . lower ( ) if ( extension in ( 'csv' , 'dbf' , 'fixed' , 'xls' , 'xlsx' ) ) : return extension elif ( extension in [ 'json' , 'js' ] ) : return 'json' return None
try to guess a files format based on its extension .