start python pdb with multiple arguments?
Question: I was wondering if there is a way to start pdb with multiple arguments.

Currently I know I can do this:

    
    
    python -m pdb script.py 
    

and then manually setup break points, with:

    
    
    (Pdb) break
    (Pdb) break 2
    Breakpoint 1 at /home/ozn/test2.py:2
    (Pdb) break 3 
    Breakpoint 2 at /home/ozn/test2.py:3
    (Pdb) break
    

I could also insert:

    
    
    pdb.set_trace() (or with ipdb.set_trace()
    

in different lines (which is eased by stuff like python-mode in vim). However,
if I take that approach, e.g.

    
    
    # note: break points from python-mode in vim
    print "hello "
    a = 1
    import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
    a =+1
    import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
    print a   
    i = 9 
    

I can't list all the breakpoints I have with the command `break` when inside
`pdb`. Here is example: I run the file, it produces output, and switches to
`pdb` session, but command `break` is empty:

    
    
    [2] ozn@deboz:~ $ python 1.py
    hello 
    > /home/ozn/1.py(4)<module>()
          3 import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
    ----> 4 a =+1
          5 import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
    
    ipdb> list
          1 print "hello "
          2 a = 1
          3 import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
    ----> 4 a =+1
          5 import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
          6 print a
          7 
          8 i = 9
    
    ipdb> break
    ipdb> 
    

_Ideally_ I would like to start pdb like this:

    
    
    python -m pdb script.py b 2 b 3
    

and when inside , the prompt should do this:

    
    
    (Pdb) break
    (Pdb) break 2
    Breakpoint 1 at /home/ozn/test2.py:2
    (Pdb) break 3 
    Breakpoint 2 at /home/ozn/test2.py:3
    (Pdb) break
    

Alternatively, I would be happy to run my script from within `vim` when
running python mode with some break points. Right now, it just hangs. Meaning,
if I press `<lead>r` when the code has break points in it, it will hang, or at
the best case will produce some garbage like this:

    
    
    ~                                                                               
    ~                                                                               
    ~                                                                               
    ~                                                                               
    ~                                                                               
    ~                                                                               
    ~                                                                               
    Code running.> /home/ozn/1.py(4)<module>()
                                                    3 import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
                     ----> 4 a =+1
                                        5 import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
    
         ipdb> 
    

When setting the breakpoints to be `import pdb; pdb.set_trace()`, vim
completely hangs and produces the following message :

    
    
    Code running.
    

# questions:

  1. Can my vim python-mode be better configured so it behaves with breakpoints?
  2. Do you know of a way to run "debugging scripts" or start pdb with multiple arguments? Bonus questions:
  3. Any alternatives to the plugin `vdebug` ?


Answer: **Question1:**

Yes. I also have the same problem with you when using python-mode. Vim
completely hangs and just shows '`Code running.`' I figured out that the
problem occurs at '`~/.vim/bundle/python-mode/autoload/pymode/run.vim`'.
`<leader>r` makes this script run, and the script is stuck at the line '`py
execfile(vim.eval('expand("%:p")'), context)`'. I didn't make effort to solve
this bug in the script. Instead, I use a simple script to make everything run.

I make a 'python.vim' file, paste in the following code and put the file at
'`~/.vim/plugin/after/ftdetect/python.vim`'(if you don't have this folder,
create one).

    
    
    " Python
    if executable("python")
      autocmd BufRead,BufNewFile *.py map <F5> :w<cr>:!python %<CR>
    else
      autocmd BufRead,BufNewFile *.py map <F5> :echo "you need to install Python first!"<CR>
    endif
    

What we need is to run python code and pdb in vim, right? It works now!
However, when you press `<F5>` in a python file in vim, it will jump out the
vim to run python in terminal, and when the python program finishes, it will
automatically jump back to vim. It's ok if you like it.

However, I have found **a better way.** Just install a vim plugin called
'**conque** ', <https://code.google.com/p/conque/> , and install '**iPython**
'. Then, you should change the 'python.vim' code as following.

    
    
    " Python
    if executable("python")
      autocmd BufRead,BufNewFile *.py map <F5> :execute 'ConqueTermSplit ipython '.expand('%:p')<CR>
    else
      autocmd BufRead,BufNewFile *.py map <F5> :echo "you need to install Python first!"<CR>
    endif
    

Now, it will split a window to run python code for you just inside the vim
when you press `<F5>`.

![enter image description here](http://i.stack.imgur.com/z1WaM.png)

**Question 2 & 3:**

I did't know a multiple arguments way to run pdb. Maybe you can customize the
code above to achieve this.But I can recommend you a cool graphical python
debug tool in vim, called 'vim-debug'.

You can get 'vim-debug' from <http://jaredforsyth.com/projects/vim-debug>

Hope these help! :)

