When I have to deal with bugs in Python code, I often insert breakpoints so during execution I'm being dropped into the debuger when a breakpoint is reached. I've been mostly using pdb (command line) and pudb (ncurses interface).
Is it possible to launch winpdb instead in such situation? What's the breakpoint code I shall include in my python script so winpdb would get started?
Edit: I'm using a simple text editor (vim) for writing code. Please do not suggest me to use an IDE instead, which has winpdb integrated or has its own GUI debuger that is similar to winpdb.
Winpdb is normally used so that you run the script with winpdb:
winpdb myscript.py
If you want to start it from "inside" python instead, the documentation on how to do that is here: http://winpdb.org/docs/embedded-debugging/
Related
I'd like to be able to launch and attach a debugger at a specific point in some python 3.6 code without having to be attached to it from the program start. .NET has this via Debugger.Launch(), where when that statement is hit I am prompted to attach a debugger.
Is there something like this for Python 3.x?
import pdb;pdb.set_trace()
use above statement to debug command code,step in(s), step out(o),next(n), continue(c) and read official documentation python with pdb it will nice core dubugger of python 2 and python3
What is the benefit of running code through the command prompt/terminal vs an ide?
I've noticed recently when using the progressbar module of python that the progress text is updated on the same line in the command prompt window while the ide prints each text on the next line. Why are these different? Are they not running though the same interpreter?
The IDE adds an extra layer of software between the program and the python interpreter.
What you are seeing is probably that the IDE's output window is not a complete terminal emulator, and doesn't understand or ignores the commands that the progressbar module uses. to keep the output on the same line.
Have a look at ipython. It is a very nice environment for testing and running python code.
Each IDE is infact interacting via the command line and redirecting streams into it's implementation of showing those outputs, Each IDE has it's own way of doing this, command prompt is more powerful if you are expeirienced and easy to try one off scripts, try ipython which is great for beginners and learners alike for fast access to the programming environment and trying out module.
I've been trying to find this information online but I'm not getting the answer.
I've used RStudio and Geany for editing files before. Now I'm trying to use ViM to edit python and R files (I know there's RPy, but nothing to do with my problem).
I would like to know how can I have 3 terminals (could also be vim buffers, or screen windows) with one running ViM and the others running R and Python. When I execute a Python script, the terminal (window or buffer) with python shows the output. The same when I run R scripts.
I would appreciate insight on this as this is something that's keeping me from using ViM regularly. I would also consider a solution with terminator terminal multiplexer or guake terminal. Any information about sending code for scripting from one instance to another is welcome.
Are you looking for a way to have a REPL inside Vim? If so, Vim wasn't really designed with that in mind, though there are some plugins that try. Conque is an example.
Some things I use to have a quicker code/run/test iteration with Python:
IPython's %edit feature, which starts editing a script with $EDITOR and will run the script after you exit.
vim-ipython which can send/execute/recieve code via an IPython interpreter.
tmux which allows you to have multiple shells side by side, but with little interaction between them.
Vim-slime is a general-purpose solution to this I'm pretty happy about, it will send blocks of code to any tmux pane, meaning it works for any language.
https://github.com/jpalardy/vim-slime
Your requirements for online information may not have been spelled out in enough detail, since I seem to find a wealth of information on using ViM as an IDE for both R and Python:
R:
http://www.r-bloggers.com/r-with-vim/
http://www.vim.org/scripts/script.php?script_id=2628
http://www.vim.org/scripts/script.php?script_id=1048
Python:
http://wiki.python.org/moin/Vim
http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/
Have a look at vim-ipython, a plug-in for Vim.
You need to download the source (linked above), and run the Vim command :source path/to/file/ipy.vim.
Start by running a new IPython session (e.g. using IPython qtconsole or IPython notebook) and then type :IPython into Vim. Your Vim is now connected to the IPython instance you just opened.
You can press F5 to run the whole python script in your Vim, or Ctrl+s to run the current line. Ctrl+s will also run whatever is selected if you're in visual (i.e. 'select') mode.
I've noticed how easy it is to debug a Python script from Eclipse. Simply set breakpoints and run a Python script from the debug menu. But is it possible to start a Python Interactive Interpreter instead of running a particular Python script, whilst still having Eclipse breaking on breakpoints? This would make it so much easier to test functions.
Thanks for any help
Still looking for a simple/ish way to start the debugger in Eclipse->PyDev that lets me use the interactive debugger. None of the answers as of yet is acceptable
You can explicitly write code to setup a breakpoint in your script, and then "remote debug". That means having pydevd in the pythonpath of your script wherever it is running, and running the eclipse pydev remote debugger on your devbox. If it's all happening on the same machine, this is fairly straightforward.
If not, you'll need to specify the hostname of the dev machine running the python remote debugger in the call to settrace(). You'll also need pydevd available on the machine running the script.
I have got this working in the past without having to install eclipse+pydevd on the machine running the script. It's not totally straightforward, and if you go that route I'd recommend checking that the pydevd versions match or at least you know they're compatible. Otherwise you end up wasting time debugging the debugger.
For details see: Pydev Remote Debugger
what about this, in the script, you can write a function, say onlyForTest, then each time you write a new function and want to test it, you can just put it in the onlyForTest function, then specify some arguments required by the new function you just write, then open the interactive python shell, import the script, call the onlyForTest function, check out the result.
I am using Eclipse as a Python IDE. Is there anyway for me to Debug my program and break to an interactive prompt. I am interested in exploring the existing data and running/testing commands.
I believe there has to be a way, but I am so used to compiling languages that I have not been able to find where the options are.
Any ideas?
You can easily do that by using PDB (Python Debugger) inside a python shell.
Look at http://docs.python.org/library/pdb.html for more info.
Anyway I believe Eclipse will let you inspect you data when setting a breakpoint.