3 ms·
Python, too. Let's say you import some code that does this, somewhere deep inside: try: x = 1 / int(s) except ZeroDivisionError, ValueError:
by raldi 9y ago
Python, too. Let's say you import some code that does this, somewhere deep inside:
try:
x = 1 / int(s)
except ZeroDivisionError, ValueError:
print "uh oh"
Oops, you just accidentally overwrote what the term ValueError means, in a way that won't get you a warning or anything. But somewhere else, far away, when you try to refer to ValueError, you're going to get really weird bugs and have no idea where they're coming from, since the stack trace will be nowhere near the code with the bug.
- cesarb 9y agoThat particular gotcha has been fixed in Python 3: >>> try: ... x = 1 / int(s) ... except ZeroDivisionError, ValueError: File "<stdin>", line 3 except ZeroDivisionError, ValueError: ^ SyntaxError: invalid syntax It now requires the "as" keyword. Also, AFAIK setting ValueError to something else affects only the current module; only modifying __builtins__.ValueError would affect other modules.