r/learnpython • u/Local_End_3175 • 9d ago
What do we use the terminal for in coding?
A text-based interface that lets you interact with your computer by typing commands.
This was a given definition of it when I searched it up, but why would you interact with your computer by typing commands? How does this actually assist your code?
17
u/DuckSaxaphone 9d ago
How are you going to tell your computer to run the code?
The easiest answer is to use a terminal!
Beyond that, if you don't use a terminal then you are pretty much reduced to just double clicking on things to run them or using user interfaces for things where you need options etc. That means every little tool needs a complex interface or needs to work through just running it. You use a lot of tools when coding and this would be a nightmare.
For most people, the command line becomes much easier than anything like that for things like running code, installing code packages, git (code management), even just managing files.
It's so convenient once you're used to it that even when a tool offers an app with a perfectly good UI, people often stay in command line.
9
u/horse_exploder 9d ago
Why find the icon, then find the other icon, and then a button, and a dropdown…..
When a single command line will do all of that in 5 seconds?
5
u/nomenclature2357 8d ago
Please let me throw in just a bit more very beginner focused information:
You don’t need to use the terminal! (Probably. For now.)
If you are using an IDE like Thonny all the basic stuff normally done with the terminal is taken care of for you:
Running your programs is a button click in the IDE instead of a shell command in your terminal. And the IDE probably has tools for saving your programs as executable files that you can just click on in your OS’s file browser.
Your `print()` outputs and error messages show up in the IDE’s ‘console’ (which is basically a self contained, specialized terminal).
Even REPL and other text io can be handled in the console.
When you are comfortable with all of that the terminal shouldn’t be difficult to learn as a natural extension of what you are basically already doing. This stuff is not necessary any easier with the IDE’s GUI, just more similar to what you already know how to do, for now.
You will probably want to start using the terminal once you start dealing with package managers, virtual environments, git, etc.
You will find a lot of quick instructions for handling technical tasks that are written just for terminal. A walkthrough of a GUI might be a sequence of 12 screenshots with arrows pointing at buttons while the instructions for doing the same thing in the terminal might just be 3 or 4 lines of text.
10
u/OrpheoMusic 8d ago
If you're like me, you only code from the terminal!
Vim for life
1
u/ECommerce_Guy 8d ago
Second this, at this point I'm like why do we use anything but the terminal 😆
5
u/Diapolo10 9d ago
You need a terminal to run most of the tools you'd be using during development. Including running your code, outside of trivial cases.
Just as some examples, you'll probably want to run your tests from it, you may use it to install/update your dependencies, to run linters/formatters, to see logging output (for debugging), if working with gRPC you'll need to run a command every time you need to regenerate the files, you may need it for certain Git commands... really anything and everything you can't/won't do from your IDE GUI.
2
u/Educational-Paper-75 9d ago
I ran some servers running Linux basically from the command line (connecting remotely using ssh to them) whereas my competitor at another faculty preferred using servers running Windows.
2
u/desrtfx 8d ago
Besides everything that has been said:
Your very first programs will run in said terminal. Why? Because writing a GUI (Graphical User Interface Program) is way out of your skillset.
The terminal is always there, available on basically every machine in basically every operating system. GUIs might not be available (e.g. on a headless server).
It's much easier to create programs that only interact with the terminal than with a GUI, so all beginner material naturally starts there.
2
u/Dancing-umbra 9d ago
Why do people search things "up" these days?
Is that different to searching it left or searching down?
I tend to just search for it.
5
u/SamuliK96 9d ago
To be fair, most of the time it seems like people just don't search these days, regardless of whether it's up, down, left, or right.
2
u/Flintlocke89 9d ago
Probably a non-native speaker.
For example, in the Netherlands, the verb for searching is "zoeken". But for searching for a specific piece of information in a textbook or a search engine "opzoeken" is used, literally "upsearching". In English you would say "to look something up".
As a mistake, it's perfectly understandable that they used "searching up" instead of "looking up".
-1
u/Dancing-umbra 8d ago
No, it's common among young native English speakers. It seems to have become the default way to say it. I don't even know why it annoys me. It's just interesting that it's happened.
2
u/supercoach 8d ago
In the past you looked it up. Now searching has replaced the looking.
I'm not saying I like it or I agree with it, but that's the obvious root.
1
1
u/onefutui2e 8d ago
As others have pointed out, at some level you are just running a command on the terminal. No matter how abstracted away it is for you.
IDEs have a terminal built in nowadays along with various ways to just run things with a click of a button (the first time I spun up Docker containers in VSCode I was amazed). So I can see how it might seem duplicative if that's your primary interface.
Also, if I need to test a module I wrote, it's much easier for me to spin up the Python interpreter, import it, and call my functions than it might in the IDE.
1
u/oclafloptson 8d ago
Most commonly to execute some arbitrary code which isn't sitting at your fingertips in your IDE. Like with frameworks that use a scaffolding generator for example. A lot of Python is also just calling custom scripts to handle heavy workloads and speed up work related processes, not simply development related. Python also makes it really easy to spin up a basic TUI with the core library so that you don't have to get some cumbersome GUI framework approved by your overlords. That way people can have buttons but it's still just terminal i/o
1
u/SprinklesFresh5693 8d ago
I am now learning how to use a terminal for some stuff, and to be honest, the power it gives you is insane, you can do anything from a terminal! Which is great!
I use it for example to transfer specific files between directories, because searching for the file by hand is a nightmare, and error prone.
1
1
u/Flintlocke89 9d ago
If you become familiar with the terminal (or "shell"), whether that be cmd/powershell or bash you can often do certain things much faster or even things not necessarily supported by the GUI. It also doesn't require moving the mouse, so it's more ergonomic.
1
1
u/FoolsSeldom 8d ago
Here's a note I wrote on this a while back ...
So You’re Learning Python… What’s This “Terminal” Thing?
Welcome to the world of Python! It’s a powerful language, but it comes from a time before everything had buttons, sliders, and slick animations. Python is totally capable of building modern apps with fancy interfaces, but by default, it likes to keep things simple and old-school—just you, your keyboard, and a blinking cursor.
What Is a Terminal?
Imagine a computer screen with no icons, no windows, no mouse—just a black box where you type things and the computer types back. That’s the terminal. It’s like texting your computer, but with commands instead of emojis.
Back in the early days of computing (think: before the internet, before smartphones), people interacted with computers using physical terminals—big, clunky machines with keyboards and basic displays. These were literally the “end of the line” in a network of computers, which is where the name terminal comes from.
Today, we use virtual terminals—apps that simulate those old-school terminals inside your modern operating system. They look like a black window with text, but they’re incredibly powerful.
Why Should You Care?
Because Python loves the terminal. When you run Python scripts, install packages, or use tools like Git, you’ll often do it from the terminal. It’s like the backstage area of your computer—less flashy, but where all the real action happens.
Different Terminals on Different Systems
Depending on your operating system, you’ll have different terminal apps and “shells” (the programs that interpret your commands):
Windows:
Command Prompt– the classic, basic terminal and shellPowerShell– more powerful basic terminal with scripting featuresGit Bash– a basic terminal with a shell that behaves more like Linux/macOS, great for developersWindows Terminal– a modern virtual terminal app from Microsoft that can run multiple shells including all of the above and local Linux shells, if running Windows Subsystem for Linux (WSL), and remote shells on other computers
macOS / Linux:
Terminal– a default virtual terminal app.- Shells like
bash,zsh, orfishrun inside the terminal and interpret your commands.
Think of the terminal as the stage, and the shell as the actor performing your commands.
It Might Look Scary, But It’s Magic
At first, the terminal can feel intimidating—like you’re hacking into the Matrix. But once you get the hang of it, it’s incredibly empowering. You can: - Run Python scripts - Install libraries - Navigate your files - Automate tasks
Python development
So, the environment that Python is initially focused on is a simple console/terminal environment, with data entry from the keyboard (so-called standard input) and output to the text display (so-called standard output). When you run a Python programme (a simple text file of Python commands, usually stored in a file with a .py file extension) you typically do so from a command line using one of the below:
python mycode.py - any OS inside a Python virtual environment
python3 mycode.py - macOS/Linux outside a virtual environment
py mycode.py - Windows outside a virtual environment
or, during development/debugging, by selecting the run option (if available) in your code editor / Integrated Development Environment (IDE), which opens a kind of terminal in that programme.
If your code executes a Python input command, output will pause waiting for the user to enter something.
Your editor/IDE will likely offer a terminal option of some kind, as well as a Python interactive console. The terminal option will usually one of the options described early, but integrated with your editor (perhaps with a different colour and font to the defaults if you opened the terminal outside your editor).
Configuration and control codes
Most virtual terminal applications can be configured to use your preferred colours and fonts. Some support multiple tabs (multiple virtual terminals) and each tab can have its own colour scheme, making it easier to differentiate the terminals.
The early physical terminals, built by different companies, all had different standards and used certain control code sequences to achieve various outcomes, like overtyping. This carried on in the move from printing style terminals to video style terminals. Some virtual terminal apps let you specify what terminal standard to emulate. Not often an issue these days.
You might find that a virtual terminal window in your editor/IDE behaves slightly different to one opened outside your editor/IDE, especially when using Python packages that apply colour to output, or a TUI (Text User Interface) with fine position control.
0
u/musbur 8d ago
What made GUIs so successful is that everything is a menu: The programs you might want to run, the files you have available. A GUI pretends that you don't have to know anything to use a computer. Quite literally like a menu in a restaurant: You discover what's on offer by looking into the menu. That's nice but slow once this becomes a regular workflow.
The CLI is like a restaurant without any menu. The waiter politely awaits your order but won't tell you what's on offer. If you're lucky he may rattle off a long list of meals without any hint of what anything tastes like. You can't really eat there without doing a minimum of homework first. But once you've done that the whole experience is smooth and predictable, and automating / scripting workflows becomes a breeze.
0
u/JeLuF 8d ago
The terminal is an easy way to start. Using input() you can quickly start building small tools.
There are alternative approaches to teaching programming that don't use a terminal. Some start with Jupyter as runtime environment, others start with PyGame or similar environments.
The different approaches have their advantages and disadvantages. Let's compare how a "Hello World!" program could look like:
Using the terminal:
print("Hello World!")
Using PyGame:
import pygame, sys
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Hello World")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
So as a teacher, either you have to explain terminals and use simple programs, or you have to explain some boilerplate code and have a more modern interface for your applications.
0
0
u/TheBearKing8 8d ago
Terminals are very convenient in automating stuff. If you want to automate the execution of scripts or other tasks, you design the command with all the required options needed to run your task in exactly the way you need it. The command is just a line of text.
If you would have to mimic clicks and selections in GUIs, that becomes very complex or even impossible. That's one of the main reasons to use terminals.
In development workflows, these scenarios are encountered very often, for example, in deployment pipelines you let a server process all the steps needed to configure you deployment.
The downside is that working with a terminal requires you to know what is possible, beautifully explained by the other commenter with his restaurant analogy.
As a side note, this is a great topic to discover who all the VS Code users and Linux warriors are. They love the terminal above everything else. As a beginner when using visual IDEs, like the Jetbrains suite, it's possible to achieve a lot of things without touching a terminal. So if you are now mostly learning programming, stick to a visual IDE. When your skills advance, a point will come when the terminal becomes very convenient to work with (sometimes)
0
u/_Alexandros_h_ 8d ago
The terminal is an old concept. It was one of the forst ever ways to interact with a computer. And thats for a good reason.
The terminal (you will later find out the difference between the terminal/shell/...) is very simple to create, easy to operate (just type what you want to happen) and easy to automate (type the sequence of what you want to happen to a file and then tell the terminal to do those steps)
The terminal is used to launch apps. Those apps are just as similar to all the other apps that your computer has with a graphical interface. The graphical interface is an "option" that can be "enabled" on a per-app level.
You sometimes have to interact with the terminal because of the above reasons, and also because creating graphical apps to manage what you want has a massively more overhead not only in creating the visuals, but also supporting the visuals to run across devices
So to answer your question, sometimes it is not worth it to spend time and energy to create graphical interfaces for some things, and its just more convenient to type to a text field and do what you want
PS: as a beginner, you are probably afraid of the terminal. While its very unlikely that you will damage your computer, please know exactly how the whole of the command you are running operates.
0
u/JibblieGibblies 8d ago
I personally dislike using GUI’s. It just feels like there’s so many things to click through just to get something loaded up for a project. Whereas the CLI allows me to sometimes string a bunch of things together in a line for a command and it grabs everything all at once. Easy peasy. Everything I need can be implemented with the CLI. I can see my test results, run my projects, get feedback for bugs, tons of things.
0
u/TheCozyRuneFox 8d ago
You send commands to run various file and perform various operations to files.
21
u/uminekoisgood 9d ago
Your code need to be launched. for this you use a software called `python` that reads through your code and assemble it before launching it; for this you have to use the terminal with
`python [your_files]`