终端:通过单击stacktrace lin打开编辑器

2024-06-16 14:50:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望python stacktrace行像终端中的超链接一样工作。我最喜欢的编辑器应该打开文件并转到正确的行:

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终端,但我可以切换到另一个终端。在

示例:我想单击File "/home/foo_eins_dt/foo_mail/tests/EditTest.py"和文件编辑测试.py应该在289号线打开。在


Tags: 文件inpy终端homefoolinedt
2条回答

我不认为任何终端都支持这种现成的功能。我的终端(Mac上的iTerm)在我命令单击文件名时打开文件。但它忽略了行号。在

另一方面,研究具有Python支持和嵌入式终端的ide。它们中的一些更有可能支持您的用例。在

对于因特网的未来:这在iTerm 2的OSX中是可能的

这是我的设置和崇高的文本:~/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/

相关问题 更多 >