Python Error Messages

Charles G Waldman cgw at fnal.gov
Thu Sep 9 06:25:37 EDT 1999


jonathon writes:
 > 
 > 	The current exasperating error message:
 > 
 > 	Traceback (innermost last)
 > 	  File "mass.py", line 21102 in ?
 >             print changed_field, " is record_list[28] "
 >           File "mass.py", line 20610 in print_web_page
 >             table_prefix = "<tr><td> "
 > 	  TypeError:  illegal argument type for built in operation.
 > 
 > 	**********************************************************
 > 
 > 	Line 20607 et al are:
 > 
 >    make_table = '</p><p> <TABLE align = "center" border = "5" cellpadding = "5" cellspacing = "5" frame = "box" width = "95%" bgcolor = "#333333" rules = "all"  ><caption>'
 >    caption = '"Stamp Data" </caption>'
 >    table_prefix = "<tr><td> "
 >    table_break = " </td><td> "
 >    table_suffix = "</td></tr> "  # line 20610
 >    title_name = (title_prefix + country_name + bang_two + scott_data + bang_two + michel_data )
 >    add_keywords = ( pre_keywords + country_name + country_section_name + scott_data + michel_data + y_t_data + s_g_data + minkus_data + end_of_line )
 >    file_description = ( pre_describe + description_prefix + country_name + bang_two + country_section_name + bang_two + scott_data + bang_two + michel_data + end_of_line )
 > 

It seems pretty likely to me (but this is just a guess!) that the
error is on the line:

add_keywords = ( pre_keywords + country_name + country_section_name +
 scott_data + michel_data + y_t_data + s_g_data + minkus_data +
 end_of_line )

Somehow one of the variables is not a string, and the 'addition'
operation fails.  

Welcome to dynamic typing!

The "TypeError" is pretty explicit, the "built in operation" is
addition, and one of the arguments is a type for which this operation
doesn't make sense - such as string + integer, or string + None, etc.

Yes, it would be nice if the error message were a little more
detailed, like "TypeError:  Illegal argument type (None) for built in
operation (add)", for instance.

What seems most annoying to me, and I really don't have a clue about,
is why you're getting an off-by-one error on the line number.  Is
there something strange about this file perhaps?

By the way,  I'd write the line in question as:

add_keywords = "%s%s%s%s%s%s%s%s%s" % (pre_keywords, country_name,
	     country_section_name, scott_data, michel_data, y_t_data,
	     s_g_data, minkus_data, end_of_line )

This avoids creating a bunch of String objects to hold the
intermediate results of all the additions, and also provides coercion
to string type in the case that one of the arguments winds up being
non-String.





More information about the Python-list mailing list