Curious string behavior

James Henderson james at logicalprogression.net
Wed Jan 28 12:34:46 EST 2004


On Wednesday 28 January 2004 5:22 pm, mark wrote:
> I've encountered an anomaly while using the string module (specifically,
> string.split).  Here's the snippet:
>
> import string
>
> address2 = ' '
> line = 'function, dealer, type, firstname, lastname, vin, blank'
> print 'Address2 Type (first check): ', type(address2)
> function, dealer, type, firstname, lastname, vin, blank =
> string.split(line, ',')
> print 'Address2 type (second check): ', type(address2)
>
> I've extracted this from a larger script, but the error happens roughly
> the same way.  Now, here's what I would expect to see:
>
> Address2 Type (first check):  <type 'str'>
> Address2 type (second check):  <type 'str'>
>
> Here's what I get instead:
>
> 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\scriptut
> 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
>
> What the heck is going on here?  I figure I'm just missing something.

You've masked the function "type" with a string called "type", the value of 
which is " type".

James
-- 
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/





More information about the Python-list mailing list