"Overload" class execute method I already learned that you can't and don't need to overload in Python, but I didn't know how to call it otherwise.

(all pseudo code)

I have a button:

myBox = layout.box()
myBox.operator(my_Button.bl_idname, text = "Move it") 


And want to add a non-obligatory parameter to the execute method:

class my_Button(bpy.types.Operator):
   bl_idname = "object.my_button"
   def execute(self, context, calledByButton=True):   


So I can call the method by using the button, or somewhere in the script:

bpy.ops.object.my_button(False)


But I get an error on registering it (strangly for the next class)


  ValueError: expected Operator, my_NextButton class "execute" function to
  have 2 args , found 3


How would I do that correctly?
You do this correctly like this:

import bpy

class MyButton(bpy.types.Operator):
    bl_idname = "object.my_button"
    bl_label = "My Button"
    flag = bpy.props.BoolProperty(default=True)

    def execute(self, context):
        if self.flag:
            print('Called by button')
        else:
            print('Not called by button')

 bpy.utils.register_class(MyButton)

 #usage:
 myBox.operator("object.my_button").flag = True
 bpy.ops.object.my_button(flag=False)