I need to run a script several times, which among other things adds a custom function to a handler list. How can I check that it doesn't eist already, so as not to have several identical functions in my handlers list, without clearing the list altogether?

This doesn't work.

import bpy

def test(self):

if not test in bpy.app.handlers.render_pre:

1 Answer 1


You can use a list comprehension to check if your function already exists:

def myFunc():
    """Your function"""

if not myFunc.__name__ in [hand.__name__ for hand in bpy.app.handlers.save_pre]:

It'll get the function's name from the pointer for each function in your handler list. Then, you can compare it to your function's name.

[hand.__name__ for hand in bpy.app.handlers.save_pre]

It's equivalent to:

handlerList = []
for handler in bpy.app.handlers.save_pre:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .