what about it doesn’t work? are you getting an error? unexpected behavior? going to need more than a block of code that says “doesn’t work”. at a glance, your indents are off- that would certainly throw an exception.
Make sure you have an Info panel open and refer to the System Console for errors. My machine immediately pointed me to the problem area, of course I had to fix the indentation issues first.
I would also warn you against assuming the modifier will be named “Array” it’s also possible that your newly created empty won’t be called “Empty”. You may want to look into giving them unique names.
A better way would be to avoid using the operators and just create the empty manually. That way you have a reference to it, and don’t need to rely on the name of the object. Edit: also worth noting that if you do it this way you also have to add it to the scene collection manually as this isn’t handled by the object factory
for example:
# create the empty. if there's already an object named "array", the object
# factory will append a numeric identifier to it, ie) 'array.001'
empty_obj = bpy.data.objects.new("array", None)
bpy.context.collection.objects.link(empty_obj) # bpy.context.collection is the last collection you interacted with, most likely the scene collection.
Yup. In general it is best to avoid operators in your addons. I’ve only recently discovered the power of this. It really takes a lot of digging to find the work arounds to using operators, though. I wish someone with a lot more time than me could write a cross reference. I’m starting to get the hang of it and finding more ways to avoid operators as I do more addons.