views:

61

answers:

3

Hi, I keep getting the following error:

AttributeError: Caribou instance has no attribute 'on_key_up'

The problem is, I'm pretty sure I do have that attribute...

Here are some excerpts from my code (from 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

And this is the line that is causing the error:

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

Anybody see what I'm doing wrong?

Thanks!

edit: Whoops--here's how I create the caribou instance:

caribou = Caribou()
+1  A: 

You aren't showing your import statements or how "caribou" the instance is being created. My guess is you are trying to pass caribou.on_key_up as in caribou the module, not the instance.

manifest
I didn't import caribou because I defined the class in the same .py file. As for how the instance is being created, please see the edit.Thanks for the reply!
FallSe7en
+2  A: 

What happens if you print dir(caribou)? Do you see your method?

UberJumper
This is what I see:['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']It's weird though, because I should have a class called 'Caribou' (this is where the on_key_up function is) and a function 'usage'
FallSe7en
do you have a file called....Caribou.py? In the same folder?look for any files called import Caribou do you see anything?
UberJumper
Yea--the file is called 'caribou.py'. Inside that file is the class 'Caribou' and the function 'usage'.
FallSe7en
+3  A: 

The OP mentions in a comment that dir(caribou) gives him:

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

so it definitely looks at that point that caribou is a module -- nothing else would normally have __builtins__ etc. The error message however clearly mentions a Caribou instance -- so I imagine that something else must be happening between that dir call and the following attempt to access caribou.on_key_up.

Clearly the OP is having some multiple use of that beloved caribou identifier (at some point it's bound to a Caribou instance, but at other times it's clearly a module, and indeed the OP does mention a caribou.py which is clearly going to become a module named caribou when imported).

So my recommendation is to clarify naming. For example, use

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.

Alex Martelli
Thanks! That was it!
FallSe7en
@FallSe7en, you're welcome!
Alex Martelli