Terry J. Reedy <tjre...@udel.edu> added the comment: A new Stackoverflow question gives a better illustration of how special-casing KeyError can be a nuisance. https://stackoverflow.com/questions/46892261/new-line-on-error-message-in-idle-python-3-3/46899120#46899120 >From a current repository build instead of 3.3:
>>> s = 'line\nbreak' >>> raise Exception(s) Traceback (most recent call last): File "<stdin>", line 1, in <module> Exception: line break >>> raise KeyError(s) Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'line\nbreak' > The OP wanted to get the line break to break without fudging the code to catch Exception rather than KeyError. I proposed catching KeyError and then 'print(err.args[0]' instead of 'print(err)'. Why this makes a difference, and why KeyError is unique in needing this, is obvious after I found this issue and read the code comment quoted by Amaury. But it sure wasn't before. The rational for applying repr only applies when there is exactly one arg of value ''. So I think the fix should be to only apply it when args *is* ('',). There is no reason to quote a non-blank message -- and suppress any formatting a user supplies. ---------- nosy: +terry.reedy _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue2651> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com