gpt4 book ai didi

python - AttributeError:首选项实例没有属性 '__setattr__'

转载 作者:太空宇宙 更新时间:2023-11-04 11:52:27 25 4
gpt4 key购买 nike

我的应用程序在 Windows 上运行,我正在尝试针对 Linux 对其进行配置。

我得到以下 AttributeError:

Preferences instances has no attribute 'self.setattr'

class Preferences:

def __init__(self):
"""
Default preferences are imported from parameters
file at each creation of an object.
The database default is not automatically
updated (file schema.sql). On Preferences parameters change,
schema.sql should be changed accordingly.
"""
with open(os.path.join(APP_ROOT, 'parameters.json')) as parameters:
json_data = json.loads(parameters.read())

# for each att(ribute) from preference file,
# create an attribute in Preferences Object
# which is a Preference object
for att in json_data['preferences']:
self.__setattr__(
att,
Preference(
**{label: json_data['preferences'][att][label] for label in json_data['preferences'][att]}))

最佳答案

您的类确实没有 __setattr__ 方法。你要做的是

setattr(self, name, value)

代替

self.__setattr__(name, value)

关于python - AttributeError:首选项实例没有属性 '__setattr__',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55629611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com