Re:Goto in Python
by emidln on Monday September 21, 2015 @10:18AM
(#10252413)
I've seen exceptions masquerading as goto in the wild in multiple python codebases (and not because I added them). `raise HttpResponse(status=401, body="unauthorized")` inside some utility method is little more than goto exit in a lot of C code.
[ Parent
| on HN ]
Using Exceptions this way in Python code is common practice and considered "Pythonic" and it's different than goto:
- an Exception only can bubble up the call stack, not to an arbitrary location in the code
- it can be caught whatever level during that path