# Function to set component property

**URL:** <https://forum.inductiveautomation.com/t/function-to-set-component-property/15074>\
**Category:** Ignition\
**Created:** [August 15, 2017, 7:51pm UTC](https://forum.inductiveautomation.com/t/function-to-set-component-property/15074 "2017-08-15T19:51:46Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2017, 10:59pm UTC](https://forum.inductiveautomation.com/t/function-to-set-component-property/15074/3 "2017-08-15T22:59:24Z")

</div>

Why wouldn’t one just use python’s `setattr()` function? Like so:

```auto
def setPropertyValue(comp, prop, val):
    setattr(comp, prop, val)

```

Consider catching AttributeError, though, to fall back on the setPropertyValue() method applicable to custom properties (not always supported by setattr). Like so:

```auto
def setPropertyValue(comp, prop, val):
    try:
        setattr(comp, prop, val)
    except AttributeError:
        return comp.setPropertyValue(prop, val)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/function-to-set-component-property/15074)._
