12

I am new to python programming.I have a python script and I am trying to profile it using cProfile command. I typed the following

python -m cProfile -o readings.txt my_script.py

It generated readings.txt. But when I try to open the file using any standard text editor or notepad, the file doesn't open properly. It doesn't contain the data

Can anyone please tell me how to store these statistics into an external file that can be opened using notepad??

I am using windows platform

4

1 回答 1

17

cProfile -o模块生成的输出文件不是纯文本的;它是一个序列化的pstats.Stats对象。我通常不使用该-o选项,而是将标准输出重定向到我要创建的文件中。

python -m cProfile -s time my_script.py > profile.text 2>&1

否则,您只需要使用pstats模块来读取文件并检查其内容(请参阅上面链接的文档)。

于 2014-01-31T00:14:09.900 回答