[_] Python Question
Matthew Wilkes
matt at matthewwilkes.name
Mon Dec 28 11:25:03 GMT 2009
On 2009-12-28, at 1136, jan.grant at bristol.ac.uk wrote: > I still don't get it, Father Ted. Explain to me again why it's > better..? It's just the Python philosophy, both are correct, but exception is the standard. What you're saying by using an exception is "Append this to the list at attributes[value]", then telling it that if that list doesn't exist ("except KeyError") it should create a new list with the element you were going to append as the first element. The point is, instead of programming all the different cases you can think of you programme the default case and what to do if there is a problem. Of course, just catching exceptions can't cover all possibilities, sometimes you need to use if statements. Matt