【发布时间】:2014-05-26 22:41:16
【问题描述】:
我正在尝试加载 cProfile 配置文件,进行一些排序和微调,然后将结果输出到文件中。基于documentation,我想我可以简单地传递一个文件对象,print_stats 函数将重定向到该流。
这是我尝试使用的代码:
import sys,pstats
s = open('output.txt', 'w')
p = pstats.Stats('profile.dat', s)
这是产生的错误:
TypeError: Cannot create or construct a <class pstats.Stats at 0xbaa870> object from '<open file 'output.txt', mode 'w' at 0xb2ef60>''
我还应该补充一点,当我不将对象传递给流参数时,输出在终端中显示正常。
【问题讨论】:
标签: python-2.7 cprofile pstats