Execute Python code line by line, like VBA?

Question:

I’m new to python and I’m having fun. So far I’ve only been on the road in VBA and SQL, but one thing bothers me. Is there no feature that goes through the code line by line like in VBA? This has always helped me a lot with VBA (F8), I could check the value of the variable on the fly (hold mouseover), i could check the whole code better and see where exactly it is running on a bug. Is this function not really available in python? I use PyCharm as IDE

Thanks!

Asked By: Mr.Shazam

||

Answers:

You may try the following command: python -m pdb <script.py>. It will run the script in the Python debugger where you can traverse your code step by step.

Answered By: vpetrigo

There is nothing like VBA/VB6 IDE for python, unfortunately. Microsoft’s IDE is simply unmatched in terms of debugging convenience. As a language, Python is more powerful, but good debugging solution is yet to come, you can’t chance lines execution order or alter code on the fly in the debugger.

Answered By: Anatoly Alekseev

Yes, not as fine as you can do in VBA, but in Pycharm you can actually click on the gap between the line number and the code, it will add a red circle there meaning that’s as stop point much like VBA, just like pressing the F8 key to advance a line.

To run the code in debug mode on PyCharm, just right click anywhere in the code and select "Debug ‘mycode.py’" (cn’t miss the green bug icon).

But when I say ‘not as fine as VBA’ it’s mainly because unfortunatelly, unlike VBA, you can’t edit your code while running on debug mode.

Answered By: vfoltz
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.