How can I reload a UI operator instead of creating a copy of it when I run a script?

I set up an operator script where I move the active object 5 units in the x axis every time I click on the operator. However, every time I click "Run Script", a new operator is made to be clicked on instead of updating the first one. What code can I write to only have one operator copy that I can update over time?

Here's my code:

import bpy
from bpy.types import Operator
from bpy.props import FloatVectorProperty, FloatProperty

class TestClass(Operator):
'''Test Class'''
bl_description = "test description"
bl_idname = "object.test"
bl_label = "Test Label"
bl_options = {"REGISTER", "UNDO"}

def execute(self,context):
context.active_object.location.x += 5
return {"FINISHED"}

@classmethod
def poll(cls, context):
ob = context.active_object
return ob is not None and ob.mode == 'OBJECT'

self.layout.operator(
operator = TestClass.bl_idname,
text = TestClass.__doc__,
icon = "QUESTION")

def register():
bpy.utils.register_module(__name__)

def unregister():
bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
register()

• bpy.types.INFO_MT_add.remove(add_it) in the unregister()? Nope: But you can always use F8 to reload all scripts. – florianfelix Jul 6 '16 at 23:05
• F8 does work. Do you know what button there is to click that's the same as F8? Also, do you know where the "remove" function is in the documentation? Even though it didn't work, I'd like to look it up, but I can't find it. – DragonautX Jul 6 '16 at 23:15
• I can't find it either in the documentation (well hidden). F8 doesn't have a button. – florianfelix Jul 6 '16 at 23:21
• Oh ok. I wish they had it. And alright. I've noticed I can always type Reload Scripts after pressing spacebar. – DragonautX Jul 6 '16 at 23:30
• Actually, I found that remove() (and append(), just to add it on) can be found in older versions of the blender documentation, like here, in Blender 2.61.4. It's apparently a Menu() method. bpy.types.Menu.append, and then "Autocomplete" in the console can give you a description. – DragonautX Jul 6 '16 at 23:53

When you add or alter something in your adddons register() function you also need to undo that change in unregister(). For your menu item that means adding bpy.types.INFO_MT_add.remove(add_it)
The other issue you have is running the script in blender's text editor. When you do this the code after if __name__ == "__main__": will be run, if you want to test your addon like this then add an unregister() call before the register() call. You will want to put the unregister in a try block to catch unregistering before the first register.
• You can add the unregister() call to your script, before the call to register() so you can run your addon script inside blender, here is an example – sambler Jul 7 '16 at 7:13