Python Desciptors

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

Here is the code:

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

    def __get__(self, obj, objtype):

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

    def __str__(self):
        return str(
class exeEngStepper(object):

    def __init__(self, exeEngStepID):

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

Here is the output:

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

Per the docs, those methods only work when owned by a parent class. 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.

I can certainly try that. I must have miss understood the definition. I was following this How To and I thought it was basically the same.

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.)

Ah that makes sense now. Thanks!