python - 如何从 PyCharm 中的输出控制台跳转到源代码?
问题描述
寻找一种能够通过单击控制台中的某些输出行(类似于 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
提前致谢 !
解决方案
为每个有同样问题的人回答这个老问题。
日志输出需要包含这部分:
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)
推荐阅读
- javascript - ReactJS->为什么我的产品会这样显示?
- r - 在 RMarkdown 文档中使用参考书目时,如何在 RStudio 中使用 --citeproc 而不是 pandoc-citeproc?
- html - Bootstrap 导航栏中的容器
- android - 将 Android Gradle 插件更新到 4.1.0 后,构建失败并出现异常
- flutter - Flutter:按产品获取值的总和
- c++ - 如何输出具有 a[0] - a[0]a[1] - a[0]a[1]a[2] 的数组
- haskell - 在 Haskell 中按第一个元素和第二个元素对元组列表进行排序
- sass - Scss:多个 BEM 状态类
- python - 如何使用opencv将多对象掩码溢出到只有一个对象的掩码
- azure - 如何仅授权从我的 Frontdoor 到我的 Web 应用专用端点的流量?