8

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.

wwii
  • 23,232
  • 7
  • 37
  • 77
Ninja Bug
  • 275
  • 1
  • 2
  • 8
  • 5
    Simply use any command line text editor you have installed on the machine... vi, vim, nano, etc. `nano file.py` – rickjerrity May 18 '18 at 22:02
  • 1
    `.py` files are text files. You might want to broaden your question/search to text fiiles – wwii May 18 '18 at 22:12

4 Answers4

18

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

Kirill Korolev
  • 966
  • 3
  • 9
  • 22
  • 1
    Those are good options, in my opinion the easiest way is by using nano. Also it is important in some cases to use SUDO command, otherwise you will not be able to save your changes. – Daniel González Cortés Aug 09 '19 at 13:44
4

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

Scott Ertel
  • 117
  • 1
  • 2
2

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)

ProDigit
  • 31
  • 2
-1

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

$ vi myFile.py
Samuel
  • 781
  • 5
  • 22