Why the KeyError?
Steve Juranich
sjuranic at condor.ee.washington.edu
Fri Oct 6 14:05:45 EDT 2000
Inside of a member method, I'm getting the following error:
>>> framelist.apply_breaks()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "Frame.py", line 189, in apply_breaks
syl_idx = self[time].syl
File "Frame.py", line 104, in __getitem__
return self.data[key]
KeyError: 5.77
When I fire up the interactive mode, I see the following interesting result:
>>> framelist.data.has_key(5.77)
0
>>> x = filter(lambda k: 5.7 < k < 5.8, framelist.data.keys())
>>> x.sort()
>>> for k in x: print k
...
5.71
5.72
5.73
5.74
5.75
5.76
5.77
5.78
5.79
Which _clearly_ shows that 5.77 IS one of the keys. Could anybody please
explain to me why I'm getting this error? Could it be that I'm using floats
as dictionary keys? I know that the internal representation of them is
kinda dodgy. Is there a way around this, or should I just re-index using
ints?
Thanks for the help.
----------------------------------------------------------------------
Stephen W. Juranich sjuranic at ee.washington.edu
Electrical Engineering http://students.washington.edu/sjuranic
University of Washington http://rcs.ee.washington.edu/ssli
P.S.: I'd just like to say that the more I use Python, the more convinced I
am that Python rocks! Of course the language itself is sheer beauty, but the
numerous _helpful_ websites and this NG are one heck of an icing on an
already delicious cake!
Please pardon the excessing use of bangs (!), but I just get excited when I
start talking about Python.
More information about the Python-list
mailing list