【问题标题】:Kernprof (line_profiler): how to output result as text instead of a binary fileKernprof(line_profiler):如何将结果输出为文本而不是二进制文件
【发布时间】:2019-05-03 15:47:58
【问题描述】:

运行kernprof时:

kernprof -l script_to_profile.py

输出存储在二进制文件中,可以在终端/命令行中读取。

有没有办法将结果输出到文本文件?

这似乎是有用的功能,但在文档或其他帖子中找不到。

【问题讨论】:

  • 阅读您提到的页面(在发布此问题之前)-> 但我认为它没有提到输出到文本文件。
  • kernprof 输出到标准输出,因此将其重定向到文件。
  • 默认情况下,输出是一个二进制文件(至少在我的系统上)-> 即需要通过发出命令来读取它:“python -m line_profiler script_to_profile.py.lprof”,这将将内容打印到命令行。我希望直接输出到文本文件。我错过了什么?
  • 听起来他们一定是改了。不幸的是pip install line_profiler 在当前版本中是broken,所以我无法安装最新版本。无论如何,你不能做类似python -m line_profiler script_to_profile.py.lprof > profile_output.txt的事情吗?

标签: python python-3.x line-profiler


【解决方案1】:
python -m line_profiler script_to_profile.py.lprof > profile_output.txt

将二进制输出转换为文本文件(感谢@martineau)

【讨论】:

    猜你喜欢
    • 2020-06-24
    • 2016-07-12
    • 2019-01-24
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 2015-05-17
    相关资源
    最近更新 更多