def is_filelike(obj):
 if (isinstance(obj, str) or isinstance(obj, unicode)):
  return False
 res = True
 for a in ('read', 'tell', 'seek'):
  res = (res and hasattr(obj, a))
 if (not res):
  raise ValueError('Invalid object passed as file')
 return True

def is_filelike ( obj ) : if ( isinstance ( obj , str ) or isinstance ( obj , unicode ) ) : return False res = True for a in ( 'read' , 'tell' , 'seek' ) : res = ( res and hasattr ( obj , a ) ) if ( not res ) : raise ValueError ( 'Invalid object passed as file' ) return True
filename or file object? .