You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决AttributeError: 'super' object has no attribute '__getattr__'错误

问题解决思路

错误原因分析

  1. 第一个错误AttributeError: 'super' object has no attribute '__getattr__':

    • 存在参数拼写错误:**kwarge应为**kwargs
    • 核心问题是在__init__方法中直接访问self.ids——Kivy的ids字典是在组件的KV布局解析完成、Widget树构建完毕后才生成的,__init__执行时ids还未初始化,此时访问self.ids.input2会触发属性查找失败,进而导致super对象的__getattr__报错。
  2. 第二个RecursionError:
    修改后的super(ScreenMain(), self).__init__(**kwarge)是错误写法——ScreenMain()会直接实例化当前类,导致__init__被递归调用,最终超出Python的递归深度限制。

修正后的代码

class ScreenMain(Screen):
    def __init__(self, **kwargs):  # 修正参数拼写
        super(ScreenMain, self).__init__(**kwargs)  # 正确的super调用

    def on_kv_post(self, base_widget):
        # 该方法在KV布局解析完成后触发,此时ids已可用
        original_text = self.ids.input2.text
        reshaped_text = arabic_reshaper.reshape(original_text)
        self.ids.input2.text = get_display(reshaped_text)

补充说明

  • 如果使用Python 3及以上版本,super调用可以简化为super().__init__(**kwargs),无需显式传入类和实例参数。
  • on_kv_post是Kivy组件的生命周期方法,专门用于在布局加载完成后执行需要访问ids的逻辑,是替代__init__中操作ids的标准方案。

内容的提问来源于stack exchange,提问作者zyadpc20

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 03:42:08