Obscure Exception message

Bjorn Pettersen bjorn at roguewave.com
Thu Jun 8 17:42:37 EDT 2000


"Daley, MarkX" wrote:
> 
> Hi, all!
> 
> I'm still trying to catch up on my Python reading (>50 messages!), but I
> have a problem with a while loop I'm using.  Hope someone can help.
> 
> alphadict = {}
> for i in range(len(result)):
>         c = 1
>         serialnum = result[i][6]
>         try:
>                 while serialnum in alphadict[c]:
>                         c = c + 1
>                 alphadict[c] = alphadict[c] + [serialnum]
>         except KeyError:
>                 alphadict[c] = serialnum
> print len(alphadict)
> 
> The print len(alphadict) is there to let me know if it has done the job or
> not.  Basically, I anticipate the length being >1.  Here is the exception
> message.
> 
> Traceback (innermost last):
>   File "C:\Program Files\Python\Pythonwin\pywin\framework\scriptutils.py",
> line 237, in RunScript
>     exec codeObject in __main__.__dict__
>   File "C:\Program Files\Python\cit.py", line 63, in ?
>     while `serialnum` in alphadict[c]:
> TypeError: string member test needs char left operand
> 
> I have no idea what this is telling me, although the 'char' comment makes me
> wish I had a flamethrower!

It seems to be telling you that serialnum (or is it really `serialnum`
as in the errormessage) is not a single character. I.e. you can't do
something like "if 'bar' in 'foo bar baz'" (you'll need string.index for
that).

hth,
-- bjorn




More information about the Python-list mailing list