# Python Desciptors

**URL:** <https://forum.inductiveautomation.com/t/python-desciptors/38531>\
**Category:** Ignition\
**Tags:** python\
**Created:** [September 9, 2020, 5:05pm UTC](https://forum.inductiveautomation.com/t/python-desciptors/38531 "2020-09-09T17:05:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dandersen](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dandersen](https://forum.inductiveautomation.com/u/dandersen)\
**Post date:** [September 9, 2020, 5:05pm UTC](https://forum.inductiveautomation.com/t/python-desciptors/38531/1 "2020-09-09T17:05:44Z")

</div>

Having an issue with descriptors in Python. Are the ` __get__ ` and ` __set__ ` not supported?

Here is the code:

```auto
class tagger(object):
    def __init__ (self, tagPath):
        self.tagPath = tagPath

    def __get__ (self, obj, objtype):
    	print("get")
        return system.tag.read(self.tagPath).value

    def __set__ (self, obj, val):
    	print("set")
        system.tag.write(self.tagPath, val)

    def __str__ (self):
        return str(system.tag.read(self.tagPath).value)
        
class exeEngStepper(object):

    def __init__ (self, exeEngStepID):

        self.exeStepID = exeEngStepID
        self.completeC = tagger("[default]ExecutionStepList/exeEngStep" + str(self.exeStepID) + "/completeC")
       
tc = exeEngStepper(1)
type(tc.completeC)
print(tc.completeC)
tc.completeC
tc.completeC = 12
type(tc.completeC)

```

Here is the output:

```auto
<class ' __main__.tagger'>
111
< __main__.tagger object at 0x15>
<type 'int'>

```

---

<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:** [September 9, 2020, 5:29pm UTC](https://forum.inductiveautomation.com/t/python-desciptors/38531/2 "2020-09-09T17:29:09Z")

</div>

Per the docs, those methods only work when [owned by a parent class](https://docs.python.org/2.7/reference/datamodel.html#implementing-descriptors). Not free-form. I recommend you implement **getattr** and **setattr** on your `exeEngStepper` class itself, where the tagpaths are managed within exeEngStepper. Or use the `@property` decorators.

---

<div class="post-metadata">

**Author:** ![dandersen](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dandersen](https://forum.inductiveautomation.com/u/dandersen)\
**Post date:** [September 9, 2020, 5:41pm UTC](https://forum.inductiveautomation.com/t/python-desciptors/38531/3 "2020-09-09T17:41:07Z")

</div>

I can certainly try that. I must have miss understood the definition. I was following this [How To](https://docs.python.org/2.7/howto/descriptor.html#descriptor-example) and I thought it was basically the same.

---

<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:** [September 9, 2020, 5:45pm UTC](https://forum.inductiveautomation.com/t/python-desciptors/38531/4 "2020-09-09T17:45:20Z")

</div>

No, you’re trying to use `tagger` as an instance variable (with `self.`), where that example shows the assignment to `x` at the _ **class** _ level, the same level as method definitions. (No access to the containing class’s instance variables.)

---

<div class="post-metadata">

**Author:** ![dandersen](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dandersen](https://forum.inductiveautomation.com/u/dandersen)\
**Post date:** [September 9, 2020, 5:46pm UTC](https://forum.inductiveautomation.com/t/python-desciptors/38531/5 "2020-09-09T17:46:50Z")

</div>

Ah that makes sense now. Thanks!
