<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"> <div>I appologize...but what is, 'grep'? I'm at the end of my rope, which right now looks about as sturdy as string (and I don't mean a string buffer either)!!!</div> <div> </div> <div>Okay, where to go from here... Again, as I mentioned there may be holes in what I'm giving but that's because 1). segments of this program do work, and I don't want to overload this list with my Python problems (and believe me, I have enough to probably keep you kind, knowledgable folks busy for weeks!) and 2). I don't always know if I'm giving you all enough information to decipher my mess, or too much information. </div> <div> </div> <div>I believe 'NEWI' is supposed to be a new subkey that will hold a value called 'newind.' But if I can't get the program to initialize this 'NEWI' then I don't know how any values can come from
it. </div> <div> </div> <div>Thanks anyways... I'll keep digging,</div> <div> </div> <div>Sara<BR><ALAN.GAULD@BTINTERNET.COM><BR>"Sara Johnson" <SARLIZ73@YAHOO.COM>wrote<BR>> Probably best if I skip the example and show what code I do have:<BR>> ~~~~~~~~~~~<BR>> for key in h.keys():<BR>> wssd=h[key]['WSSD']<BR>> wspd=h[key]['WSPD']<BR>> wmax=h[key]['WMAX']<BR>> newi=h[key]['NEWI']<BR>> if wssd<-989. or wspd<-989. or wmax<-989.: break<BR>> if wspd==0.: break<BR>> ~~~~~~~~~~~~~~~~~<BR>> Where the "newi" = "abcd" that I showed before.<BR><BR>OK, Then that is telling us that h is a dictionary containing<BR>further dictionaries inside. The error tells us that at least one<BR>of the dictionaries does not have a key 'NEWI'<BR><BR>If this code is supposed to be production strength it is not of good<BR>quality. It should either be defending these dictionary accesses<BR>with a try/except block or it should be using
the get() method<BR>of the dictionary to force a default value. (The tests at the end<BR>are poorly written too. If one of my team produced code like<BR>this I'd be having strong words with them!)</div> <div> </div> <div><BR>Which is the best solution will depend on the situation...<BR><BR>> I have no where else in my code anything pertaining to<BR>> these 4 keys.<BR><BR>Might I suggest grep? :-)<BR><BR>> The first 3 were there, and produce no errors. I am making<BR>> adjustments to an existing script. I only have C programming<BR>> knowledge<BR><BR>I hope you have at least basic Python too? Otherwise even<BR>reading the code will be difficult. While Python is easy to read<BR>thats a strictly relative measure!<BR><BR>> so my thought was that it "newi" was just a variable that<BR>> needed to be assigned.<BR><BR>newi is indeed a "just a variable" that is being assigned a value,<BR>but the value does not exist. This is a data error, your
problems<BR>lie in the initialisation of the dictionaries coupled to the <BR>vulnerability<BR>of the code to this kind of error.<BR><BR>> You'll notice the parameters below (i.e., if wssd < -989 ) but<BR>> there is obviously nothing for "newi" at the moment.<BR><BR>Indeed, but there may be further on. Its certainly not involved<BR>in any of these tests.<BR><BR>> The program's only error at the moment seems to be this line:<BR>><BR>> newi=h[key]['NEWI']<BR><BR>The program has several errors IMHO but the one that is causing<BR>the interpreter to complain is due to non existent data.<BR>You need to find why that data is missing.<BR>Or, you could find a valid default value and assign that, either<BR>through a try/except block or by uysing a get() instead of<BR>key access.<BR><BR>-- <BR>Alan Gauld<BR>Author of the Learn to Program web site<BR>http://www.freenetpages.co.uk/hp/alan.gauld <BR></div></BLOCKQUOTE><p> 
<hr size=1>Get the Yahoo! toolbar and <a href="http://us.rd.yahoo.com/evt=48225/*http://new.toolbar.yahoo.com/toolbar/features/mail/index.php">be alerted to new email </a>wherever you're surfing.