3 ms·
It's also worth noting that this won't work in Python before 2.5 (or maybe 2.4).
by j_baker 17y ago
It's also worth noting that this won't work in Python before 2.5 (or maybe 2.4).
- kevindication 17y agoIn 2.3 it does. Why wouldn't it?
- j_baker 17y agoI swear I read that this behavior changed somehow in Python 2.5. But I'm not sure how. But it does at least appear to work in python 2.4.
- kevindication 17y agoIn 2.5 they made try/except/finally possible.
- josephkern 17y agoYou mean after 2.5 right? try: return True finally: return False -- There's an error in your program: * 'return' outside function ... Just sayin'
- paulbaumgart 17y agoIt works if you put it in a function (2.5.1): >>> def test(): ... try: return True ... finally: return False ... >>> test() False
- Jach 17y ago2.6.2 as well. I liked this little snippet, though I grumbled a little on the inside and would be appalled if I ever found something like that in serious code...