Python - changing the default stacktrace format displayed in the terminal

Let's take a typical stacktrace running Python on the command line:

Traceback (most recent call last):
  File "", line 654, in <module>
  File "/myapp/venv/lib/python3.6/site-packages/click/", line 764, in __call__
  File "", line 172, in __init__
    self.di = self.loadyaml(section_stepnames.bme_load)
  File "", line 124, in loadyaml
    return di[section]
KeyError: 'bme_load'

I am on OSX, using iTerm2 which allows you to click on stuff and launch a matching command (typically, what's been associated with the file extension).

this open the file, but just at the top, or leaves the cursor where it is if it's already open:

enter image description here

This is nice, I can launch my editor right from here, and Sublime will open my file.

However... if instead of "", line 124, I just had "":124,

then Sublime would open the file at line 124.

  • Visual Studio Code - requires code -g ""
  • Vim vim +124 """

These might be more difficult to get working, but I assume it could be done.

I realize you can format the stack output within a Python program. However, is there a way to change the default representation of the file name and line number so that one can open the file right from the terminal?

What I want:

this will open the file right at line 124 and will move the editor to line 124 there if it's already open.

enter image description here

And in Visual Studio's own terminal, this also opens at line 124:

(the trick there is to start the line as a file path)

enter image description here