Force anything to be a string.

jonathon jblake at stamp-coin.com
Sun Sep 19 01:39:33 EDT 1999


On Sat, 18 Sep 1999, Tim Peters wrote:

>[jonathon]
>> 	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. ]
>
>Using the builtin str function was the correct approach from the start.
>>From the error msgs you're getting, it looks most likely that you
>accidentally rebound the name "str" to a string, so "str" no longer refers

	Aaarrgh.  I ran the script with the statement
	print str, " is the trapped string."
	I totally expected the script to fail.

	Instead, it printed out a string "MMMMM"	

	A little poking around, and I found an object called
	str in two modules that the script calls.   After changing
	the name of those variables, that error disappeared.  :-)

>to the builtin function (builtin function names are not reserved, which is
>both a feature and a bug <0.7>).

	A bug, IMNSHO.   A really bad bug, since I wasn't even using a
	module I wrote.   

>The error msg there should look familiar.  It's telling you that the syntax
>looks like a call, but the object in the caller's position *can't* be called
>("call of non-function"); and it's also giving the type of the object that
>can't be called (str is of "type string").

	Another piece of wisdom to add to the list of things I
	couldn't find in _The Python Library Reference Manual_.

>diagnosis-may-be-easier-than-cure-ly y'rs  - tim

	I found a neat little script xref.py, that produces a cross
	reference for a file.  Threw it at my program, and then the
	modules, and found the very_badly_named_variables, that were
	causing those error messages.  
	
	xan

	jonathon





More information about the Python-list mailing list