Think about using shebang line, so you will be able to use it with still any language, not only Python.
Adding shebang:
Add this to first line of your script:
#!/usr/bin/env python3
or this, if you are using Python 2:
#!/usr/bin/env python2
Vim keymap:
Add this to your ~/.vimrc
:
nmap <F7> :w<cr>:!clear;"%:p"<cr>
Make file executable:
Type in Vim:
:!chmod +x %
or in terminal:
chmod +x script_name.py
Explanation:
When F7 is pressed in normal mode, Vim will try to execute current file as bash script. Then bash interpreter will see shebang line and understand, that this file should be passed to Python (or any other programm if needed).
Also you will be able to run your script from terminal using it's name:
./script_name.py
instead of this way (that will work too):
python3 script_name.py