【问题标题】:How to jump to source from output console in PyCharm?如何从 PyCharm 中的输出控制台跳转到源代码?
【发布时间】:2018-06-01 07:57:23
【问题描述】:

寻找一种能够通过单击控制台中的某些输出行来跳转到代码行的方法(类似于 eclipse 功能) 我当前的输出如下所示:

C:\anaconda3\python.exe C:/test/TestUnit.py 
2018-06-01 10:43:26,610 TestUnit.py              <module>() 8    INFO     TestUnit started, checking input params ...
2018-06-01 10:43:26,610 TestUnit.py              <module>() 27   INFO     Provided video file: [D:\input\video.mp4]
2018-06-01 10:43:26,613 Video.py                getFrames() 4    INFO     Extracting frames from input video D:\input\video.mp4

是否可以点击 getFrames() 并让 IDE 跳转到文件 video.py => getFrames() 函数中的相关代码行?

看起来像这样:

class Video(object):
 def getFrames(video,log):
   log.info("Extracting frames from input video " + video) <<====== jump to this

提前致谢!

【问题讨论】:

  • Ctrl+Mouse left click 在目标函数上
  • 在我的 IDE PyCharm 控制台中,打印输出是纯文本,表示不可点击,使用 Ctrl+鼠标左键单击它不起作用

标签: python ide pycharm


【解决方案1】:

为遇到相同问题的每个人回答这个老问题。

日志输出需要包含这部分:

File "/path/to/file.py", line 140

使用 Python 的日志记录模块,您可以做到这一点

format="File \"%(pathname)s\", line %(lineno)d"

这是一个完整的日志配置示例

logging.basicConfig(level=10, format="[%(asctime)s] %(levelname)s [File \"%(pathname)s\", line %(lineno)d] %(message)s", datefmt="%H:%M:%S", stream=sys.stdout)

【讨论】:

    猜你喜欢
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2015-03-23
    • 1970-01-01
    相关资源
    最近更新 更多