I use a vim that has Python interpreter compiled in.
I source a python file that has this function:
def pyterm(filename="", interactive=1):
cmd = "%s %s %s " % (PYTHON, "-i" if interactive else "", filename)
if "DISPLAY" in os.environ:
return run_config(os.environ.get("XTERM"), cmd)
else:
return os.system(cmd)
And map it to a keyboard shortcut:
nmap ;ru :update<CR>:python pyterm(vim.current.buffer.name, 0)<CR>
nmap ;ri :update<CR>:python pyterm(vim.current.buffer.name, 1)<CR>
I had previous set some environment variables to determine the exact terminal to run in if using gvim, or in the same terminal if not in a X.
Then I usually just type ';ri' in a Python buffer to run it (usually to test it).