Ninja Bug
Ninja Bug

Reputation: 291

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.

Upvotes: 8

Views: 153795

Answers (4)

ProDigit
ProDigit

Reputation: 51

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)

Upvotes: 3

Scott Ertel
Scott Ertel

Reputation: 117

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

Upvotes: 4

Samuel
Samuel

Reputation: 781

You can simply use an editor such as vi, vim or nano:

$ vi myFile.py

Upvotes: -1

Kirill Korolev
Kirill Korolev

Reputation: 1006

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

Upvotes: 18

Related Questions