簡體   English   中英

AttributeError:首選項實例沒有屬性“ __setattr__”

[英]AttributeError: Preferences instance has no attribute '__setattr__'

我的應用程序在Windows上運行,我正在嘗試為Linux配置它。

我得到以下AttributeError

首選項實例沒有屬性“自我”。 定居

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)

使用setattr而不是__setattr__

https://docs.python.org/3/library/functions.html#setattr

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM