Message191083
| Author |
mark.dickinson |
| Recipients |
barry, brett.cannon, mark.dickinson, r.david.murray, rhettinger |
| Date |
2013年06月13日.15:47:53 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1371138473.77.0.567799776638.issue18163@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
+1. I recently chastised a colleague for doing "raise KeyError(long_message)" instead of "raise KeyError(missing_item)". When I went to the standard library to support my POV, I found (to my chagrin) a big mix of the two styles.
>>> from collections import ChainMap
>>> d = ChainMap({}, {})
>>> try:
... d.pop('not there')
... except KeyError as e:
... key, = e.args
...
>>> key
"Key not found in the first mapping: 'not there'" |
|