python - 终端:通过单击堆栈跟踪行打开编辑器

标签 python terminal editor

我希望 python 堆栈跟踪行在终端中充当超链接。我最喜欢的编辑器应该打开文件并转到正确的行:

Traceback (most recent call last):
  File "/home/foo_eins_dt/djangotools/utils/smtputils.py", line 73, in _inner_to_outbox
    return func(*args, **kwargs)
  File "/home/foo_eins_dt/foo_mail/tests/EditTest.py", line 289, in test_something
    beleg_ids=importutils.import_msg_file(temp)
TypeError: bar() takes exactly 2 arguments (1 given)

到目前为止,我使用的是 gnome-terminal,但我可以切换到不同的终端。

示例:我想点击 File "/home/foo_eins_dt/foo_mail/tests/EditTest.py" 并且应该在第 289 行打开文件 EditTest.py。

最佳答案

对于互联网的 future :这在 OS X 中是可能的 iTerm 2

这是我使用 Sublime Text 的设置:~/bin/magic-iterm-open.py

#!/usr/bin/python

import sys
from subprocess import call

if len(sys.argv) > 2:

    pathToSubl = "/Users/rainer/bin/"

    filename, linenum = sys.argv[1], sys.argv[2]
    rest = "" if len(sys.argv) < 4 else sys.argv[3]

    if not filename.endswith('.py'):
        # I believe this approximates iTerm's default
        call(['/usr/bin/open', filename])
    else:
        newLinenum = linenum
        if not str.isdigit(linenum):
            line = linenum.split(",")
            if len(line) > 1:
                newLinenum = filter(str.isdigit, line[1])

        command = ["{0}subl".format(pathToSubl),
                   "--add",  # If you'd like to add to your current sublime project
                   "{0}:{1}".format(filename, newLinenum)]

        call(command)

以及iTerm2中的配置:

enter image description here

所有功劳归功于旧的编辑帖子,此处:https://www.reddit.com/r/SublimeText/comments/1kanze/iterm2_jump_to_location_in_sublime_text_23/

关于python - 终端:通过单击堆栈跟踪行打开编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18847600/

相关文章:

python - 我的游戏角色只有当鼠标在屏幕上移动时才会移动,而它需要鼠标

python - 编码给出 "' ascii' 编解码器无法编码字符......序号不在范围内(128)“

macos - 我可以将命令行脚本转换为 AppleScript 吗?

emacs - 是什么让 emacs 成为一个好的编辑器?

php - 如何使用带有自定义对话框的 TinyMCE 自定义按钮来添加内容?

qt4 - 我在哪里可以找到 Qt4 源代码编辑器小部件?

Python Pandas - 从单元格中删除一个单词

python - Django 查询集 - 确保结果仅检索一次

visual-studio-code - Code-OSS 无法从终端命令 'code-oss .' 打开文件夹或文件

laravel - Vagrant:vagrant up 命令给出 "A box must be specified"错误