How to use Nano Editor to Save Python Script in Linux In Python
Step 1: Starting nano editor
To create file and starting writing python script, it follows the same command as vim but here we use “nano” instead of “vim”.
Command:
nano script.py
Output:
Step 2: Writing and Saving the script
Commands to save the script in nano. There are various commands in nano, but we are only interested in saving the script. If you want to know the commands of nano check the cheatsheet for it.
Commands:
- Ctrl + o -This command will save the script and any other stuff in the file but it will not exit the nano editor, hit enter after pressing the keys
- Ctrl + x –This will exit the nano editor, use this after saving the file successfully
Lets write a script and then save it using nano.
print(0)
if (0):
print("GFG")
else:
print("Like this article.")
Save the script: Press “Ctrl + o ” and hit “Enter” to save and then press “ctrl + x” to exit the nano editor.
Step 3: Execute the script
Executing the script is same that is :
Command:
python3 script.py
Output:
How To Save Python Scripts In Linux Via The Terminal?
Linux users like to do tasks using the terminal as it gives the user more power to do anything with the system whether it is to store, create, or remove files. Other than file management and system control tasks, the terminal is used to write scripts for any programming language. Python and Bash scripts are mostly typed using a terminal and it is best practice to do so, as it makes the programmer more versatile.
In this article, we are going to look into how can we write and save Python scripts using a terminal with terminal editors like Vim and Nano.
Table of Content
- Using Vim Editor to Save Python Script in Linux
- Using Nano Editor to Save Python Script in Linux
- How To Save Python Scripts In Linux Via The Terminal – FAQs
Contact Us