我得到錯誤「Key Error:'tempMax'」。字典鍵錯誤python
誰能告訴問題是用下面的代碼是什麼:
def catagorise(self, day, cat, f):
self.features.setdefault(cat, {f:{'high':0,'mid':0,'low':0}})
if f == 'tempMean':
if day.tempMean > 15.0:
self.features[cat][f]['high'] += 1
elif day.tempMean > 8.0 and day.tempMean < 15.0:
self.features[cat][f]['mid'] += 1
elif day.tempMean <= 8.0:
self.features[cat][f]['low'] += 1
if f == 'tempMax':
if day.tempMax > 15.0:
self.features[cat][f]['high'] += 1
elif day.tempMax > 8.0 and day.tempMax < 15.0:
self.features[cat][f]['mid'] += 1
elif day.tempMax <= 8.0:
self.features[cat][f]['low'] += 1
一天是具有變量,如平均溫度,最高溫度等物體貓是其將要投入的類別例如'霧','雨','雪','無',f是要檢查的功能,例如'tempMax'
特徵字典是在創建類時定義的。
和其餘的追溯? – MattH 2011-03-23 16:48:49
@MattH其餘的追蹤將破壞*謎語* – joaquin 2011-03-23 17:04:55