[CentralOH] Python Puzzler -- The little max bug
Eric Floehr
eric at intellovations.com
Wed Mar 11 00:38:48 CET 2015
The following code has a bug.
The code takes input and generates a dictionary of dictionaries of
dictionaries of the following form:
{
'hour1':
{ 'formula_type1': { ... },
'formula_type2': { ... },
...
},
'hour2':
{ 'formula_type1': { ... },
'formula_type2': { ... },
...
},
...
}
The symptoms were that formula types MINT, CLOUD, and PRECIP were showing
up in the final dictionary (hoursdict), but MAXT was not. For any set of
lines and hour all the formula types showed up exactly once.
What was the bug, and why was MAXT the only formula type affected?
##########################################
hoursdict = {}
for line in lines:
formula_type = ### Code to determine formula_type ###
hour = ### Code to determine hour ###
try:
hourdict = hoursdict[hour]
except:
hourdict = {}
hoursdict[hour] = {}
hourdict[formula_type] = {}
if formula_type in ('MAXT','MINT'):
parse_h1h4_formulas(f, hourdict[formula_type])
elif formula_type == 'CLOUD':
parse_cloud_formulas(f, hourdict[formula_type])
elif formula_type == 'PRECIP':
parse_precip_formulas(f, hourdict[formula_type])
return hoursdict
##########################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20150310/4fc4ff2f/attachment.html>
More information about the CentralOH
mailing list