Python Exception with custom line number and file name

  exception, python

I am processing text files that contain embedded python code. A new text file is created in which the embedded code is replaced with the result.

When embedded code raises an exception, I would like to refer the user to the location of the embedded code that caused the exception.

I don’t simply want to add this information to the exception message. I am using PyCharm where all (or most) exceptions provide a clickable link to where the Exception was raised. Is there a way to make this link point to the relevant line in the text file?

Source: Python Questions