2

I have a .py file that I am running in Terminal on my Mac, with a json file as an argument. So I run:

python file.py json_file.json

I am setting a breakpoint in the .py program by clicking the line number, but the program doesn't seem to be breaking. Is there anything else I am supposed to add?

4
  • 2
    "Clicking the line number" - do you mean in an IDE? If so, which one? And why aren't you running your code inside that IDE rather than from the terminal, if you want to use the IDE's debugging facility? Commented Oct 20, 2014 at 6:43
  • 1
    You most probably have to run/debug the script from whatever your editor is. A breakpoint is nothing that's physically written into a file. Commented Oct 20, 2014 at 6:44
  • I am only really familiar with running files in XCode. I believe this text editor for the .py file is XCode, but I do not know how to run the file with the Json argument in anything other than Terminal. Commented Oct 20, 2014 at 6:48
  • So whenever I set breakpoints in files I run in XCode, I just click the line number and it sets a breakpoint. I am wondering what is the best way to debug in a similar fashion for this Python file, if I have to do so in Terminal. Commented Oct 20, 2014 at 6:49

1 Answer 1

5

You can use pudb, which is a command-line debugger (an enhanced version of pdb).

Once you install the pudb package via pip, you simply run the script with the command python -m pudb.run my-script.py (or specifically, for your example above, python -m pudb.run file.py json_file.json) and the debugger is loaded, at which point you can set breakpoints, run to cursor, inspect variables, drop into an interactive shell, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.