[Tutor] Key Error

Bob Gailer bgailer at alum.rpi.edu
Sun Jul 8 19:20:35 CEST 2007

Sara Johnson wrote:
> Okay, it is VERY long!  So long in fact that I can't get to the top of 
> it to copy from where it begins.  Basically it's a series of codes 
> like 'WSSD' followed by values like 0.0000000000002 (more than just 
> the ones I listed, perhaps a few hundred.  The end gives the same error.
> Traceback (most recent call last):
>   File "./mymods.py", line 118, in ?
>     newi=h[key]['NEWI']
> KeyError: 'NEWI'
> I can still attach what the screen has, if that'll help.
Let's take a different approach:

print len(h)
for key in h.keys():
    except KeyError:
       print key

That will tell us how many items are in h and whether we have few or 
many of them that have the KeyError.
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC

More information about the Tutor mailing list