G'day,
I quite often map a key to do this for me. I usually use the F5 key as that has no command associated with it by default in vim.
The mapping I like to use is:
:map <F5> :w<CR>:!python % 2>&1 \| tee /var/tmp/robertw/results<CR>
this will also make sure that you've written out your script before running it. It also captures any output, after duplicating stderr onto stdout, in a temp file.
If you've done a:
:set autoread
and a:
:sb /var/tmp/robertw/results
you will finish up with two buffers being displayed. One containing the script and the other containing the output, incl. errors, from your script. By setting autoread the window displaying the output will be automatically loaded after pressing the v key.
A trick to remember is to use cntl-ww to toggle between the windows and that the mapping, because it refers to % (the current file) will only work when the cursor is in the window containing the Python script.
I find this really cuts down on my code, test, debug cycle time.
HTH
cheers,