def is_generator(obj):
 if isinstance(obj, types.GeneratorType):
  return True
 CO_GENERATOR = 32
 return bool(((inspect.isfunction(obj) or inspect.ismethod(obj)) and (obj.func_code.co_flags & CO_GENERATOR)))

def is_generator ( obj ) : if isinstance ( obj , types . GeneratorType ) : return True CO_GENERATOR = 32 return bool ( ( ( inspect . isfunction ( obj ) or inspect . ismethod ( obj ) ) and ( obj . func_code . co_flags & CO_GENERATOR ) ) )
return true if the object is generator or generator function .