Is eval the right way to go

I am pulling the commands from user prefs as text then using eval to call the function.
Is eval really the right way to go here or is there a cleaner/safer/better way
It is only evaling on commands that are already set in the user_prefs anyway.
Just like to know if there is a better way to do this
Thanks

You can, but not sure if it’s really necessary / safer:

import bpy

def getattr_from_idname(base, idname):
    ret = base
    for split in idname.split("."):
        ret = getattr(ret, split)
    return ret

op = getattr_from_idname(bpy.ops, "object.select_all.poll")
print("Poll:", op())

op = getattr_from_idname(bpy.ops, "object.select_all")
print("Operator Call:", op(action='DESELECT'))