error messages raised by python got me thinking.

Laura Creighton lac at
Sun Oct 21 15:27:15 CEST 2001

Here is a common error:
>>> f='1'  
>>> g=2
>>> f+g
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: cannot add type "int" to string
Here is another one:
>>> g+f
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand types for +

These are rather different error messages.

The reason I noticed this, is because every time I get the first
error, my initial parsing is always: f is the int, and g is the
string. I seem to expect order of the arguments as presented in the
error message to be the order in which I typed them.  I think I would
prefer 'Cannot add type string _and_ int'.  For me, adding is not something
that I do _to_ an existing thing, but something you do from top to bottom
(or in this case left to right).   Not quite the difference between a
transitive and an intransitive verb, but it has that flavour.  Perhaps 
I do not _add_ but _sum_.  [Both are transitive, but I sum the whole
set, not an individual element of the set.  In my head anyway.]

This has possible implications in how easy it is to learn python.  Am
I simply odd, or typical?  In an international world, what does
'typical' mean given than many languages don't have verb constructs
like this at all?

(Further question: why the double quotes around _int_ but not _string_?)

ever curious,
Laura Creighton

More information about the Python-list mailing list