1

我不断收到以下错误:

AttributeError: Caribou instance has no attribute 'on_key_up'

问题是,我很确定我确实有那个属性......

以下是我的代码(来自 caribou.py)的一些摘录:

 def on_key_up(self, event):
  if event.event_string == "Shift_R":
   _r_shift_down = False
  elif event.event_string == "Shift_L":
   _l_shift_down = False

这是导致错误的行:

pyatspi.Registry.registerKeystrokeListener(caribou.on_key_up, mask=None, kind=(pyatspi.KEY_RELEASED_EVENT,))

有人看到我做错了什么吗?

谢谢!

编辑:哎呀——这是我创建驯鹿实例的方法:

caribou = Caribou()
4

3 回答 3

4

dir(caribou)OP 在给他的评论中提到:

['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

所以它肯定会看到那个点caribou是一个模块——通常没有其他东西__builtins__等等。但是错误消息清楚地提到了一个Caribou instance——所以我想在那个调用和下面的访问尝试之间肯定发生了其他事情。dircaribou.on_key_up

显然,OP 对那个心爱的caribou标识符进行了多次使用(在某些时候它绑定到一个 Caribou 实例,但在其他时候它显然是一个模块,并且确实 OP 确实提到了 a caribou.py,它显然会caribou在导入时成为一个命名的模块)。

所以我的建议是澄清命名。例如,使用

caribou_instance = Caribou()

instead of binding one more value to the caribou name, and replace all uses of caribou which are supposed to be the instance (not the module) with caribou_instance. That may give you a different error, which could be more informative.

于 2010-02-28T04:13:02.393 回答
2

如果你打印 dir(caribou) 会发生什么?你看到你的方法了吗?

于 2010-02-28T00:38:51.487 回答
1

您没有显示您的导入语句或创建实例的“驯鹿”方式。我的猜测是您正试图将 caribou.on_key_up 传递给 caribou模块,而不是实例

于 2010-02-27T23:31:48.467 回答