(obj, key, value)
Set the attribute referenced by 'key' to 'value'. The key is used
    to build the name of an attribute, or attribute accessor method.

    The following attributes and accessors are tried (in this order):
    - Mapping access (that is __setitem__ for collection.Mapping instances)
    - Accessor 'setKey_'
    - Accessor 'setKey'
    - Accessor 'set_key'
    - Attribute '_key'
    - Attribute 'key'

    Raises KeyError if the key doesn't exist.
Set the attribute referenced by 'key' to 'value'. The key is used
    to build the name of an attribute, or attribute accessor method.
Set the attribute referenced by key to value . The key is used to build the name of an attribute or attribute accessor method .
def setKey(obj, key, value):
    """
    Set the attribute referenced by 'key' to 'value'. The key is used
    to build the name of an attribute, or attribute accessor method.

    The following attributes and accessors are tried (in this order):
    - Mapping access (that is __setitem__ for collection.Mapping instances)
    - Accessor 'setKey_'
    - Accessor 'setKey'
    - Accessor 'set_key'
    - Attribute '_key'
    - Attribute 'key'

    Raises KeyError if the key doesn't exist.
    """
    if obj is None:
        return
    if isinstance(obj, (objc.objc_object, objc.objc_class)):
        obj.setValue_forKey_(value, key)
        return

    if isinstance(obj, collections_abc.Mapping):
        obj[key] = value
        return

    aBase = 'set' + keyCaps(key)
    for accessor in (aBase + '_', aBase, 'set_' + key):
        m = getattr(obj, accessor, None)
        if m is None:
            continue
        try:
            m(value)
            return
        except TypeError:
            pass

    try:
        m = getattr(obj, key)
    except AttributeError:
        pass

    else:
        if isinstance(m, types.MethodType) and m.__self__ is obj:
            # This looks like a getter method, don't call setattr
            pass

        else:
            try:
                setattr(obj, key, value)
                return
            except AttributeError:
                raise KeyError("Key %s does not exist" % (key,))

    try:
        getattr(obj, "_" + key)
    except AttributeError:
        pass
    else:
        setattr(obj, "_" + key, value)
        return

    try:
        setattr(obj, key, value)
    except AttributeError:
        raise KeyError("Key %s does not exist" % (key,))
def setKey ( obj , key , value ) : if obj is None : return if isinstance ( obj , ( objc . objc_object , objc . objc_class ) ) : obj . setValue_forKey_ ( value , key ) return if isinstance ( obj , collections_abc . Mapping ) : obj [ key ] = value return aBase = 'set' + keyCaps ( key ) for accessor in ( aBase + '_' , aBase , 'set_' + key ) : m = getattr ( obj , accessor , None ) if m is None : continue try : m ( value ) return except TypeError : pass try : m = getattr ( obj , key ) except AttributeError : pass else : if isinstance ( m , types . MethodType ) and m . __self__ is obj : # This looks like a getter method, don't call setattr pass else : try : setattr ( obj , key , value ) return except AttributeError : raise KeyError ( "Key %s does not exist" % ( key , ) ) try : getattr ( obj , "_" + key ) except AttributeError : pass else : setattr ( obj , "_" + key , value ) return try : setattr ( obj , key , value ) except AttributeError : raise KeyError ( "Key %s does not exist" % ( key , ) )