Force anything to be a string.
jonathon
jblake at stamp-coin.com
Sat Sep 18 18:55:09 EDT 1999
I'm reworking a script, and keep running into this
same basic sequence of errors.
The offending lines are:
string_check = check_list[50]
string_check = str(string_check)
string_check = string.capwords(string_check)
check_list[50] = string_check
This code snippet is supposed to take the object
at check_list[50], convert it to a string, and
then capitalize each word.
#
If fed a "normal" string of characters, it works.
However, if check_list[50] is an integer, I either
see the following error message:
File "mass.py", line 20402 in align_everything(record_list)
string_check = string.capwords(string_check)
File "/usr/local/bin/python1.5/string.py" line 542 in capwords
return join(map(capitalize, split(s, sep)), sep or' ')
TypeError: arguement 1: expected read-only character buffer, int found
or I see this error message:
File "mass.py" , line 20402 in align_everything(record_list)
string_check = str(string_check)
TypeError: call of non-function ( type string )
The difference is whether I have removed the line
"string_check = str(string_check)"
#
Question:
1: How can I ensure that string_check becomes a string,
and not remain an integer? [ Other than error trapping at
the source. An option not available, since this script reads
files with bad data in them, to correct them. ]
xan
jonathon
More information about the Python-list
mailing list