News for hackers. Stuff that matters.
Re:Nerd Sniping: What does the code do at the end of the page? by j_baker on Tuesday November 24, 2009 @06:19PM (#960168)
It's also worth noting that this won't work in Python before 2.5 (or maybe 2.4).
Re:Nerd Sniping: What does the code do at the end of the page? by josephkern on Tuesday November 24, 2009 @07:18PM (#960285)
You mean after 2.5 right?

try: return True finally: return False

-- There's an error in your program: * 'return' outside function ...

Just sayin'

Re:Nerd Sniping: What does the code do at the end of the page? by paulbaumgart on Tuesday November 24, 2009 @07:41PM (#960323)
It works if you put it in a function (2.5.1):

  >>> def test():
  ...  try: return True
  ...  finally: return False
  ... 
  >>> test()
  False
Re:Nerd Sniping: What does the code do at the end of the page? by Jach on Tuesday November 24, 2009 @10:53PM (#960593)
2.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...
Re:Nerd Sniping: What does the code do at the end of the page? by kevindication on Tuesday November 24, 2009 @06:22PM (#960178)
In 2.3 it does. Why wouldn't it?
Re:Nerd Sniping: What does the code do at the end of the page? by j_baker on Wednesday November 25, 2009 @10:23AM (#961209)
I 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.
Re:Nerd Sniping: What does the code do at the end of the page? by kevindication on Wednesday November 25, 2009 @03:26PM (#961744)
In 2.5 they made try/except/finally possible.