AttributeError: 'TclError' object has no attribute 'message' (original) (raw)
Code:
except tk.TclError as e:
if "libfontconfig" in e.message:
Error:
AttributeError: ‘TclError’ object has no attribute ‘message’
kknechtel (Karl Knechtel) July 19, 2023, 7:48am 2
Exactly as the error message tells you. What do you expect to happen instead when the code runs, and why? It seems that you expect, given an exception e
, to be able to get its .message
. But that isn’t actually part of the Exception interface. Some exceptions might provide it, but not all, and apparently not tk.TclError
.
See: How to get exception message in Python properly - Stack Overflow
tjreedy (Terry Jan Reedy) July 19, 2023, 1:15pm 3
The only data attribute all exceptions have is args
, with args[0]
being the message. If e
is an exception, print(e)
prints args[0]
. Built-in Exceptions — Python 3.11.4 documentation