Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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
Python 3.x Python将属性从一个方法传递到另一个方法_Python 3.x_Function_Constructor - Fatal编程技术网

Python 3.x Python将属性从一个方法传递到另一个方法

Python 3.x Python将属性从一个方法传递到另一个方法,python-3.x,function,constructor,Python 3.x,Function,Constructor,我试图将属性从一个方法传递到另一个方法,但不确定如何将另一个方法传递到另一个方法。下面的CodeValueName和check_name是我希望通过printvalue方法传递和访问的两个属性。有什么想法吗 class Load_dict(object): def __init__(self, data): for name, value in data.items(): setattr(self, name, self._wrap(value)

我试图将属性从一个方法传递到另一个方法,但不确定如何将另一个方法传递到另一个方法。下面的CodeValueName和check_name是我希望通过printvalue方法传递和访问的两个属性。有什么想法吗

class Load_dict(object):
    def __init__(self, data):
        for name, value in data.items():
            setattr(self, name, self._wrap(value) if (value is not None) else '')
    
    def _wrap(self, value):
        if isinstance(value, (tuple, list, set, frozenset)):
            return type(value)([self._wrap(v) for v in value])
        else:
            return Load_dict(value) if isinstance(value, dict) else value

    def delta(self):
        d= list(self.lived_state.split(','))
        return(d) 

    def gg(self):
        if 'IL' in self.delta():
            print(self.delta())
        else:
            print('not')

class load_process(Load_dict):
    def __init__(self, value):
        super().__init__(value)
    
    def display(self):
        self.valuename = 'hello'
        self.check_name = self.fname if self.Age > 30 else self.lname
        print('Check :  and lived State : {} and values - {}'.format( self.lived_state, self.Description.values))
    
    def printvalue(self):
        print(self.valuename)
        print(self.check_name)

d = {'fname':'John', 'lname': 'Burns', 'Age': 34, 'Gender': None, 'State' : 'CA', 'lived_state' : 'CA,TX,NY,FL'}
e = {'Code': 'Dev', 'Description' : {'name' : 'Development', 'environment' : 'dev11', 'node' : '', 'values' : ['222', '333', '444']}}
b = load_process({**d, **e})

print(b.delta())
b.printvalue()
错误


问题是在
valuename
checkname
b
初始化之前,您正在
b
上调用
printvalue
load\u进程
类中唯一初始化
valuename
check\u name
的代码在
display中。
如果要确保在调用
printvalue
之前已初始化
valuename
check\u name
,则应在
加载进程
类中的
初始化
方法

AttributeError: 'load_process' object has no attribute 'valuename'