我的应用程序运行在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
而不是__setattr__
:https://docs.python.org/3/library/functions.html#setattr
相关问题 更多 >
编程相关推荐