Is there a way to get the line number of the error through executing a file? Let's say that I have the following code:
exec(open("test.py").read())
And the file has an error, in which IDLE pops up the following:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__
return self.func(*args)
File "C:\Users\henrydavidzhu\Desktop\Arshi\arshi.py", line 349, in runFile
exec(open(self.fileName).read())
File "<string>", line 2, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
I want to know the error statement (TypeError: unsupported operand type(s) for +: 'int' and 'str'
), and the line number. This is not a duplicate because I am using Python 3
, and not Python 2
.