我希望 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中的配置:
所有功劳归功于旧的编辑帖子,此处:https://www.reddit.com/r/SublimeText/comments/1kanze/iterm2_jump_to_location_in_sublime_text_23/
关于python - 终端:通过单击堆栈跟踪行打开编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18847600/