Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Properties 如何更改对象属性';的子属性,以便能够从属性设置器(重新)设置对象?_Properties_Attributes_Parent Child_Python 3.8 - Fatal编程技术网

Properties 如何更改对象属性';的子属性,以便能够从属性设置器(重新)设置对象?

Properties 如何更改对象属性';的子属性,以便能够从属性设置器(重新)设置对象?,properties,attributes,parent-child,python-3.8,Properties,Attributes,Parent Child,Python 3.8,各位: 我已经为这个问题绞尽脑汁好几天了,不知您是否能帮我: 我已经用两个数据点定义了一个给定对象,并用一个子对象的属性,使用这些属性,对给定的两个数据点执行函数,以某种方式存储对它们的回答 现在我想通过属性设置器访问子对象,以重置主对象的数据,从而\uuuu repr\uuu重置对象 我使用Python3.8.8,我将属性和属性设置器放在如下位置 @property def Drum(self): return self.__drum #This is the sub-objec

各位:

我已经为这个问题绞尽脑汁好几天了,不知您是否能帮我:

我已经用两个数据点定义了一个给定对象,并用一个子对象的属性,使用这些属性,对给定的两个数据点执行函数,以某种方式存储对它们的回答

现在我想通过属性设置器访问子对象,以重置主对象的数据,从而
\uuuu repr\uuu
重置对象

我使用Python3.8.8,我将属性和属性设置器放在如下位置

@property
def Drum(self):
    return self.__drum    #This is the sub-object, that I can return sub-properties
                           from, like ">>> Drum.PropertyA" or "Drum.PropertyB"

@Drum.setter
def Drum(self, val):
    if isinstance(val, aDrum): # ---> 'aDrum' being the sub-object type created, earlier.
        self.__drum = val
    elif isinstance(val, (tuple, list, set)):
        self.__drum = adrum(val)
    #--- here's the reset maneuvers -----------        
    dataholder1 = 1
    dataholder2 = functionB(dataholder1, self.__drum)

    
现在,我可以通过传递元组、列表、集合,甚至作为
Drum
对象本身来更改属性
Drum
的状态……但是如果我想从控制台更改如下属性,该怎么办

SomeDumbObject.Drum.PropertyA = Some_Number_Other_Than_What_Was_Initially_Set_With
因此,子对象发生了变化,这反映在主对象的
\uuuu repr\uuu

…但是调用的函数使用self.\uu-drum作为参数,其行为类似于self.\uu-drum没有更改,从它被
\uuuu-init\u \
-ed

该函数是一个
\uuu hidden\u class\u函数
,它应该接受任何
aDrum
参数,并将所需的结果返回给所需的self.\uu数据持有者

因此,在我更改子对象的参数后,下一行

dataholder2=functionB(dataholder1,自桶)

应使用已更改的自我。\u

我的问题是:为什么不呢?

提前感谢您的回答

真诚地

卡普特胚泡