26
The Start of Something Beautiful
"For millions of years mankind lived just like the animals.
Then something happened which unleashed the power of our imagination,
We learned to talk."
Quoting from the lines of Pink Floyd, it's simple to understand how communication has shaped our society, likely the single most important thing that has made civilizations stand. While we have created types of communication for us humans, since the age of machines we have learned to communicate with machines too, and surprisingly it spans back to the 40s.
I wanted to start with the history as to where do programming languages come from, as they help us understand why we are working with them. Plus it narrates a nice story on how far we have come. As we begin, today we will be discussing Import Statements. However, here's a quick look at what the first high-level language looked like.

Traumatizing, right? I agree we have come a long way from the above image to print('Hello, world!').
Let's begin!
To help us understand what and how imports work, let's assume we have a module (basically a sheet of code) named dinosaur.py that has
type = 20
[A variable]def roar(name):
... return f'{name} roars'
We can import this module in two different ways :
Import statement 1:
import dinosaur
Import statement 2:
from dinosaur import roar
Here are few general pointers for import -
dinosaur.py
creates a variable name dinosaur
and also creates another variable type
which is inside the dinosaur.py
moduleRunning Import statement 1 executes the module line by line. So, when I call the statement :
dinosaur.type
and dinosaur.roar
) we can get to our variable and function.Running Import statement 2 executes the module but only by the respective variable
roar
. So, when I call the statement :roar
to be used inside the program.There is one other rare way to import which should be avoided at all costs.
from dinosaur import *
[This causes to replace all variables in your local namespace]A namespace is the current *.py file we would be working on, or importing the statements to.
Here's a picture to understand better how variables work inside namespaces when imported.
I hope this message finds you in good health, see you next week!
26