title: Blender: Python script fail (creating simple operator)
body: <p>I'm teaching myself Python in Blender and I attempted to create a simple operator using a script. The script is below - its intention is to select four (spot) lamps in the scene and change their energy (basically, flicking the lights on and off). But when I attempt to run the script, I get a "Python script fail" error message. Can anyone see what is wrong with the code?</p>
  
  <pre><code>import bpy
  
  
  def main(context):
      for ob in context.scene.objects:
          print(ob)
  
  class LightsOperator(bpy.types.Operator):
  
      bl_idname = "object.lights_operator"
      bl_label = "Headlight Operator"
  
      @classmethod
      def poll(cls, context):
          return context.active_object is not None
  
      def execute(self, context):
          light1 = bpy.data.objects['headlight1']
          light2 = bpy.data.objects['headlight2']
          light3 = bpy.data.objects['headlight3']
          light4 = bpy.data.objects['headlight4']
  
          if light1.energy==0.0:
              light1.energy = 0.8
          else:
              light1.energy = 0.0
  
          if light2.energy==0.0:
              light2.energy = 0.8
          else:
              light2.energy = 0.0
  
          if light3.energy==0.0:
              light3.energy = 0.8
          else:
              light3.energy = 0.0
  
          if light4.energy==0.0:
              light4.energy = 0.8
          else:
              light4.energy = 0.0
  
          return {'FINISHED'}
  
      def register():
          bpy.utils.register_class(LightsOperator)
  
  
      def unregister():
          bpy.utils.unregister_class(LightsOperator)
  
  if __name__ == "__main__":
   register()
  
   # test call
   bpy.ops.object.lights_operator()
  </code></pre>