Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit a py file from terminal?

I am working in a VM via PuTTY.

Via terminal, I want to open, edit, and save a .py file. How can I do it?

Thank you for your help.

like image 489
Ninja Bug Avatar asked May 18 '18 22:05

Ninja Bug


3 Answers

The easiest way is to use vim

vim your_script.py

Edit your file and save it using :w or :x

You can also use emacs or nano

like image 61
Kirill Korolev Avatar answered Sep 20 '22 23:09

Kirill Korolev


You also have to enter a command like i to get into insert mode. Then hit esc and :wq to save and quit. If you are using terminal often it may be helpful to have a cheat sheet

like image 23
Scott Ertel Avatar answered Sep 22 '22 23:09

Scott Ertel


Either do:

python3 -i pythonfile.py

At which you'll be entering the python editor after closing the program, or

Use a text editor like nano (since it's installed by default with most operating systems), or emacs, which also is a great terminal text editor.

nano pythonfile.py

emacs pythonfile.py -nw

(-nw is a non-gui mode)

like image 30
ProDigit Avatar answered Sep 20 '22 23:09

ProDigit