How do I check if an attribute is writeable?

How can I test if an attribute is read only
From the code below I am getting

AttributeError: bpy_struct: attribute “OBJECT_OT_duplicate” from “OBJECT_OT_duplicate_move_linked” is read-only


def map_operator_from_shortcut(op, idtype,keymap_item):
    for prop in dir(keymap_item.properties):
        if prop in idtype.bl_rna.properties and not prop.startswith("_") and prop not in {"bl_rna", "rna_type",""}:
            attr = getattr(keymap_item.properties, prop,None)
            if hasattr(op,prop) and getattr(op,prop) != attr :
                print("Setting in ", op, " ", prop, " to ", attr)
                setattr(op,prop,attr)
    return op


Thanks

You could read the RNA info:

bpy.context.object.bl_rna.properties['mode'].is_readonly

Or if it’s not important if it’s read-only, write-locked, or not editable for any other reason, just use standard python

try:
    # try to modify
except AttributeError:
    pass

I thought I read that try catch blocks were to be avoided if possible.
What do you think.
Thanks for the ideas

Not in python:
https://docs.python.org/3.4/glossary.html#term-eafp

Ah but
http://www.blender.org/documentation/blender_python_api_2_63_8/info_best_practice.html#use-try-except-sparingly
So use it but not in loops

This Blender Python onion gets trickier the more layers you peal off :eyebrowlift:

That’s right, don’t put a try/except block inside a loop you are going to call a million times, instead wrap the entire loop with one - this way, it needs to be set up just once. But it also depends on the use case…