Debugging with breakpoints from the console in Python

I am trying to switch from Matlab to python. One of the nice features of Matlab is that when debugging, I can put a breakpoint in some code and do something to invoke this code from the command line. Using PyCharm + IPython, I did not find a way to do this in Python. It seems I need to run the whole script in debug mode in order to do any debugging, and not just do it from a simple command. I suppose I could write a single line of script with a command that interests me, but it seems like there should be a better way. What is Python for this?

+6
source share
6 answers

I would recommend using Python Tools for Visual Studio . This is free and open source, and although Visual Studio itself is obviously not open source, there is ( PTVS Integrated ), which comes with a free and very functional version of Visual Studio for commercial use. In addition, students and staff at most educational institutions will have free access to Visual Studio Ultimate through Dreamspark .

If your program is stopped at a breakpoint, you can open "Python Debug Interactive" (from tools-> python tools), which will open an interactive python shell with access to all the variables available in your program namespace, to a breakpoint, so same as you can do in matlab.

, "locals" Matlab, "" . , , !

, PTVS , Matlab. , , . . .

​​ Matlab ipython, Intellisense , .net-, - , , Matlab, .

, , , , ( "Ctrl + F5" "F5" ) , , .

+4

python

b(reak) [[filename:]lineno | function[, condition]]

pdb.set_trace();

.

+3

Spyder??? , Matlab. , . https://code.google.com/p/spyderlib/

PS: python, , .:) Matlab Numpy...

+2

matlab R python. , .

1- Spyder Matlab, , . , . python, , - .

2- emacs python. . -, , , , python.

3- pycharm. pycharm, ( Rstudio). , , ​​ spyder emacs. -

4. ipython, , . , - .

+2

, ipython, ipdb.

pip easy_install. Etc:

pip install ipdb

, pdb. ipython , ipdb.set_trace(), / , , ( 's' code123()) ..

import ipdb;

code000()
ipdb.set_trace();
code123()

, ? ipython ( ). .

0

, pdb.set_trace(), , .

>>> import pdb

>>> def f():
...     pdb.set_trace()
...     my_function()
... 

:

>>> f()
> <stdin>(3)f()
(Pdb) s
--Call--
> <stdin>(1)my_function()
(Pdb) 

:)

0

All Articles