Why doesn't my variable value get passed to the finally block in python
问题 This is for python 2.7.10 Perhaps I'm not using the try..except..finally block correctly. I need to check on the HTTP response code I get from a webpage. If I get a 200 code, everything is working. If I get any other code, report what code. It works fine if I get a 200 HTTP code. If I get an exception, for some reason, it gives me an UnboundedLocalError, stating my variable isn't referenced. How do I get my variable to be recognized in the finally block? Here's my code: try: conn = httplib