Curious string behavior

OKB (not okblacke) BrenBarn at aol.com
Wed Jan 28 13:25:58 EST 2004


mark wrote:

> address2 = ' '
> line = 'function, dealer, type, firstname, lastname, vin, blank'
> print 'Address2 Type (first check): ', type(address2)
> function, dealer, type, firstname, lastname, vin, blank =
> # ^ LINE ABOVE CONTAINS ERROR
> string.split(line, ',')
> print 'Address2 type (second check): ', type(address2)
<snip>  
> Address2 Type (first check):  <type 'str'>
> Address2 type (second check): 
> Traceback (most recent call last):
>   File
> "C:\PROGRA~1\Python\lib\site-packages\Pythonwin\pywin\framework\scri
> ptut ils.py", line 310, in RunScript
>     exec codeObject in __main__.__dict__
>   File "C:\Program Files\Python\test1.py", line 7, in ?
>     print 'Address2 type (second check): ', type(address2)
> TypeError: 'str' object is not callable

    	In the marked line, you assign a string to a variable called 
"type".  This means that you overwrote your reference to the type 
function that you are trying to use in type(address2).  When you "call" 
type(address2) you are now trying to call the string which you have 
assigned to the name "type".  Use a different name for your variable (a 
name that the library doesn't use) and you will be fine.

-- 
--OKB (not okblacke)
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
	--author unknown



More information about the Python-list mailing list