[python-win32] Problem with built-in str() function
John Hopkins
john@hopkinsit.com
Mon, 10 Jun 2002 19:53:12 -0700
This is a multi-part message in MIME format.
------=_NextPart_000_001C_01C210B8.73B565D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
The other day, str() "stopped working" for me. Here's what I mean.
I have this bit of code in a wxPython app:
for x in range(len(items)):
DateValue =3D items[x][1]
if DateValue !=3D 'N/A':
DisplayDate =3D '%s/%s/%s' % =
(DateValue[5:7],DateValue[8:10],DateValue[0:4])
else:
DisplayDate =3D DateValue
self.SearchList.InsertStringItem(x, items[x][0])
self.SearchList.SetStringItem(x, 1, DisplayDate)
print 'items[x][2] =3D %s' % items[x][2]
self.SearchList.SetStringItem(x, 2, str(items[x][2]))
self.SearchList.SetItemData(x, items[x][2])
Often as not the loop only iterates once (the list only has a single =
element). When this line executes:
self.SearchList.SetStringItem(x, 2, str(items[x][2]))
I get the following output:
items[x][2] =3D 3
Traceback (most recent call last):
File "LabTracker_Dev.py", line 356, in OnFindClick
self.SearchList.SetStringItem(x, 2, str(items[x][2]))
TypeError: 'str' object is not callable
This is so basic that I'm utterly lost.
I feel silly, but can anybody help me with this?
Thanks,
John
------=_NextPart_000_001C_01C210B8.73B565D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>The other day, str() "stopped working" =
for me.=20
Here's what I mean.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I have this bit of code in a wxPython=20
app:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> for x in=20
range(len(items)):<BR> &nb=
sp; =20
DateValue =3D=20
items[x][1]<BR> &nbs=
p; =20
if DateValue !=3D=20
'N/A':<BR> &nb=
sp; =20
DisplayDate =3D '%s/%s/%s' %=20
(DateValue[5:7],DateValue[8:10],DateValue[0:4])<BR> &nbs=
p; =20
else:<BR> &nbs=
p; =20
DisplayDate =3D=20
DateValue<BR> =
=20
self.SearchList.InsertStringItem(x,=20
items[x][0])<BR> &nb=
sp; =20
self.SearchList.SetStringItem(x, 1,=20
DisplayDate)<BR> &nb=
sp; =20
print 'items[x][2] =3D %s' %=20
items[x][2]<BR> &nbs=
p; =20
self.SearchList.SetStringItem(x, 2,=20
str(items[x][2]))<BR> &nbs=
p; =20
self.SearchList.SetItemData(x, items[x][2])<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Often as not the loop only iterates =
once (the list=20
only has a single element). When this line =
executes:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbs=
p;=20
self.SearchList.SetStringItem(x, 2, str(items[x][2]))<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I get the following =
output:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>items[x][2] =3D 3<BR>Traceback (most =
recent call=20
last):<BR> File "LabTracker_Dev.py", line 356, in=20
OnFindClick<BR> self.SearchList.SetStringItem(x, 2,=20
str(items[x][2]))<BR>TypeError: 'str' object is not =
callable</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> This is so basic that I'm utterly =
lost.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I feel silly, but can anybody help me =
with=20
this?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>John</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> </DIV></FONT></BODY></HTML>
------=_NextPart_000_001C_01C210B8.73B565D0--