AttributeError:Preferences实例没有属性“\uu setattr\uu”

2024-05-16 21:50:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我的应用程序运行在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]}))

Tags: infromselfjsonfordataattributelabel