0

I've wanted to try atom as a new IDE for python on macOS, and I've found people usually use the command-line to run scripts with python3 myprogram.py on unix machines.

That works for me, but in some cases I want to test a variable's value without having to add plenty of print() lines in my code, the same way I would be able to with IDLE's or replit's console, without the command-line going back to zsh.

Example with replit

Example with command line

ti7
  • 16,375
  • 6
  • 40
  • 68
  • 1
    In the terminal, only `python3` will open REPL. – Alperen Dec 03 '21 at 22:31
  • 1
    An alternative way to look at your variables' contents, which will help you in many other ways, is to use an IDE's debugger. Not sure what your experience is regarding that. PyCharm is free and has a great debugger, [here](https://www.jetbrains.com/help/pycharm/debugging-your-first-python-application.html) is how to use it. – Random Davis Dec 03 '21 at 22:34
  • What is the question? – jlandercy Dec 03 '21 at 22:58
  • @RandomDavis will try ty! – Marc Robison Dec 03 '21 at 23:56
  • Does this answer your question? [How to drop into REPL (Read, Eval, Print, Loop) from Python code](https://stackoverflow.com/questions/1395913/how-to-drop-into-repl-read-eval-print-loop-from-python-code) I think you're looking for `python3 -i myprogram.py`, but there are some other interesting answers there too. – wjandrea Dec 04 '21 at 03:24

3 Answers3

0

Just type python3 in your terminal and the python console will pop out

0

You're almost-certainly looking for PDB The Python Debugger: https://docs.python.org/3/library/pdb.html

Run your program as python3 -m pdb myscript.py

Use b to set breakpoints (so you can inspect your program state there or get into libraries), c to run up to that point (continue), and ? to explore commands .. this will allow you to inspect the live state of your program wherever you breakpoint or continue to

ti7
  • 16,375
  • 6
  • 40
  • 68
  • 1
    Not sure how I can use `b` for breakpoints in this situation, but adding `breakpoint()` in my code and then `p variable_name` to check variable state works, thank you! – Marc Robison Dec 03 '21 at 23:49
  • If you invoke pdb as a module (-m flag on your run), it'll bring you into a shell for it, but you can _also_ run pdb in your program! – ti7 Dec 03 '21 at 23:59
0

Use python3

If it doesn't work you probably don't have Python 3 installed. I recommend installing Homebrew on your macOS. https://brew.sh/

Then you can easily install Python 3 using this command: brew install python3 And additionally if you need pip3 too: brew install python3-pip

Installing packages using brew is almost the same as installing packages on Linux.