Welcome Back to Think Like A Programmer, where we break down complicated computer science concepts into bite-sized articles for you.
In today’s article we’ll be looking at what happens when you point python towards a file under the hood.
If you haven’t looked at the previous lesson on setting up your development environment for python - please do so first. That way you’ll be able to walk through all the source code that we’ve provided in this article.
You can check out the article here 👉 Setting Up Your Python Development Environment
So, without ado, let’s start our python programming language journey.
If you’re running python locally on your computer, I highly suggest using VSCode - a lot of a random guys online will claim that emacs or vim is the superior experience but they are both really difficult to pick up for a beginner.
I would say that while you are learning to code, reduce the complexity that you need to deal with and focus more on the programming side. If the program compiles, you’re good.
Functionality first, ergonomics second.
Programs
Last week, we wrote our first python program that printed out Hello World! to the screen when we ran it. If you don’t remember exactly what we did, here’s a quick recap.
First we created a new python file - I suggested calling it main.py but you can call it whatever you want
We then wrote out these few lines of code
content = "hello world"
print(content)
We then opened our terminal and ran the commands
~/UnawareSpottedGeeklog$ python3 main.py
hello world
This in turn netted us the output
~/UnawareSpottedGeeklog$ python3 main.py
hello world
~/UnawareSpottedGeeklog$
But what’s happening here under the hood?
Mental Model
I find it useful to think about all computer programs through a simple input and output model - it’s the easiest thing to use and it works surprisingly well for a large range of programs.
Let’s start from the top
We wrote a program
We ran a command called python3 main.py
We got an output
Compiled Languages vs Interpreted Languages
So what happens when we run the command?
python3 main.py
For that matter, what even is a compiled language versus an interpreted language and why does it matter?
Analogy
To make matters a bit more easily, let’s imagine that you’ve been thrust into a foreign country where you don’t speak the language.
Now, you have two choices if you want someone to help you with something: