def is_zipfile(filename):
 result = False
 try:
  if hasattr(filename, 'read'):
   result = _check_zipfile(filename)
  else:
   with open(filename, 'rb') as fp:
    result = _check_zipfile(fp)
 except IOError:
  pass
 return result

def is_zipfile ( filename ) : result = False try : if hasattr ( filename , 'read' ) : result = _check_zipfile ( filename ) else : with open ( filename , 'rb' ) as fp : result = _check_zipfile ( fp ) except IOError : pass return result
quickly see if file is a zip file by checking the magic number .