[Tutor] Maze - classes
Alan Gauld
alan.gauld at btinternet.com
Thu May 10 23:42:37 CEST 2007
"Teresa Stanton" <tms43 at clearwire.net> wrote
> Exception in Tkinter callback
> Traceback (most recent call last):
> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
> return self.func(*args)
> TypeError: unbound method direction() must be called
> with Images instance as first argument (got Event instance instead)
This usually means you missed self as the first parameter in
your method definition.
> I also did a search on the 'TypeError:' which I find funny
> because I thought Python wasn't strongly typed.
Python is strongly typed, but its not statically typed.
That is all arguments are type checked at run time based
on their ability to respond to the operations required.
Thus:
>>> def add(x,y): return x+y
...
>>> add(4,5)
9
>>> add('four',5)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in add
TypeError: cannot concatenate 'str' and 'int' objects
>>> add(5,'four')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in add
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>
Notice that the two errors are different because in the
first it sees the string and tries to apply string contatenation
with the int. In the second it sees an int and tries to add
the string. But both are type errors because the arguments
don't support the required operations.
Alan G.
More information about the Tutor
mailing list