python 文件带参数时如何使用 cProfile mod?

How to use the cProfile mod when the python file takes arguments?

我正在尝试 运行 我的 python 程序上的 cProfile mod。该程序有标志,当我尝试将标志添加到参数中时,它当前显示 "no such file or directory"。

我试过了运行宁

python -m cProfile -o resultFile "myFile.py" 

这个returns"Too few arguments"

我也试过:

python -m cProfile -o resultFile "myFile.py --flag1 val"

我得到了,"No such file or directory"

我想 运行 使用命令行给出的标志。这可能吗?

无需将完整命令作为单个参数传递。就像你一样 运行 你的脚本正常:

python myFile.py --flag1 val

您可以添加 cProfile 选项:

python -m cProfile -o resultFile myFile.py --flag1 val