pythoncommand-linecprofile

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


I'm trying to run the cProfile mod on a python program I have. The program has flags and it's currently saying "no such file or directory" when I try to add the flags into the argument.

I've tried running

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

This returns "Too few arguments"

I also tried:

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

And I got, "No such file or directory"

I'd like for this to run with the flags given from the command line. Is this possible?


Solution

  • No need to pass the full command as a single argument. Just like you run your script normally:

    python myFile.py --flag1 val
    

    You can add to that the cProfile options:

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