Print to Info or grey out a button if no object is selected - Python script
The poll function of your operator is suitable for this check indeed.
Just let it check whether an object is selected/active in the current context and return a boolean:
import bpy

class HelloObjectOperator(bpy.types.Operator):
    bl_idname = &quot;obj.hello&quot;
    bl_label = &quot;Minimal Object Operator&quot;

    @classmethod
    def poll(cls, context):
        return context.object is not None

    def execute(self, context):
        print(&quot;Hello&quot;, context.object.name)
        return {'FINISHED'}

bpy.utils.register_class(HelloObjectOperator)

When adding your operator in a panel somewhere:
layout.operator(&quot;obj.hello&quot;)

The button will automatically grey out when no object is active.