How to run a step by step code in IDLE, or a selected code fragment?

For example, I have a recruiting function, I cannot figure out how it works, so I want to run a step-by-step tracing to see what step is being performed, how it can be implemented in the standard IDLE python environment

  • Add more description to your problem. - Ep1demic Nov.
  • For example, I have a recruiting function, I cannot figure out how it works, so I want to run a step-by-step tracing to see what step is being performed, how it can be implemented in the standard IDLE python environment - Oleg Fantansky
  • attach it to your question. Click "edit" and add this text. - Ep1demic Nov.

2 answers 2

As far as I know, in the standard IDLE there is no possibility to run the code step by step.

You can use a third-party service, for example http://pythontutor.ru/visualizer/

  • 1- not a standard IDLE unknown to me :) 2- documentation says that there is a debugger 3- Although for development, IDLE (outside the classroom) usually (when it is possible to install software) is not used. This is what the creator of the language said: "It’s the process of slowing down the building process.” Now a bunch of options are available for different needs. - jfs
  • Yes, I asked about the debugger, I can’t figure it out, but thanks anyway - Oleg Fantansky
  • @OlegFantansky if you open a debugger (should see: [DEBUG ON] ) and run your script on F5 or directly into the REPL code, then by pressing the Step, Over buttons in the debugger you can move forward in steps. - jfs

Import into your pdb module

 import pdb pdb.set_trace() 

pdb is a standard debugging module for python included in the interpreter. It will be displayed in the IDLE Debugger window.

  • IMHO: As your needs grow, take a look at PyCharm Comminity Edition - this is a free Python IDE with a very good debugger. - Tihon
  • This pdb in IDLE runs. This is also a debugger, but IDLE has its own built-in debugger available from the Debug menu. - jfs
  • You can set breakpoints using the right mouse button, but this doesn't work with asynchronous calls. - Tihon
  • Checked, you can work without pdb - you must first open the debugger window, allow to inspect "globals", and in the module code (must be saved) put breakpoint through the context menu. Then you can execute the code step by step using the "step". "Go" - fulfills until the next breakpoint. - Tihon