Hissing the Python way: Getting started.

Franklin Schram
6 min readMar 21, 2023

--

Scripting languages are fun, they provide a real interactive environment to play arround. Now if you read my article on setting up a Windows investment workbench and you decided to take the plunge, you could be the proud owner of a Linux virtual machine (let’s call it a container). In the article I didn’t make recommendations as to what distribution of Linux you should be installing for a good reason: It should boil down to personal preference and use cases, yet a good starting point could be Debian. Why Debian? Because it is underpinned by strong philosophical foundations. Learn Debian and you will be able to interact with all Debian derived Operating system like Ubuntu, Mint, MX etc…

1. Interpreted vs. compiled language

So what is an interpreted language? Pretty much like guys and gals at the United Nations or at the European Parliament (you know the ones wearing headphones in that big room), some languages you don’t understand need… AN INTERPRETER. Just like any language a programming language has a words and syntax which you can write in an editor: This is what we call source code. You can save the code into a file with the appropriate extension (.py for python for instance) just like at the United Nations the code is executed directly by an interpreter, rather than being compiled into machine code beforehand. In other words, the interpreter reads and executes the program code line by line, interpreting each instruction as it goes along.

To keep things simple, for compiled language like C, C++, Java (Hum… we won’t talk about the virtual machine), the source code is translated into machine code by a compiler, which can then be executed directly by the computer’s processor.

So how do your run the python “interpreter”? That thing which translates all your instructions on the fly? Well, you can run it from the terminal by typing python3.

python3

Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

I’ll give it to you, running it in the terminal is a bit… “dry” isn’t it? That’s why some smart people came up with a better way to interact with the interpreter. Pr. Fernando Pérez at UC Berkeley started the IPython project which over time evolved into Project Jupyter. Jupyter is great for starting out with Python, fleshing out ideas and communicating them to others. We’ll look how to get started with Jupyter in the next section.

Python is just one of many scripting languages out there, I’ll just throw in a few more:

  • Bash (my favourite) and the main scripting language to interact with the Linux operating system.
  • Perl
  • Ruby
  • Awk (another favorite of mine, great for processing system text data)
  • Powershell (Windows OS scripting language)
  • Javascript (Running in your browser)
  • Lua

All have pros and cons, at the end of the day using a programming language is a matter of understanding what problem you’re trying to solve. Since interpreted languages do not need to be compiled, they enable faster development and are best for prototyping. However, interpreted languages can be slower than compiled languages, and they may not be as optimized for performance-critical applications (like a trading bot for instance). So to put in plainly, interpreted languages are great to test your ideas.

2. Meet the Jupyter Notebook, your best ally in getting started.

So how do we get Jupyter running on our system? Quick bash commands would do the trick:

  • We get Python from the system package manager (I’m using Debian so I’ll run apt)
  • We use the Python package manager (called pip) to download specific libraries for data analysis (more on that in a latter article) including Jupyter.
  • We Jupyter launch by typing jupyter notebook in the terminal

What is a package manager? A package manager is a program that automates the process of installing, updating, configuring, and removing other programs on a computer.

# We get the Python3 and Python3 virtual environement packages
sudo apt-get install python3 python3-venv

#We use the Python package manager (called pip) to download Jupyter
pip3 install jupyter

#We run jupyter
jupyter notebook

In the below terminal session I show you how:

  • We create a folder for data analysis
  • We create an empty Jupyter notebook (we could also have done this in Jupyter)
  • We create a virtual environment, activate it, install Jupyter with the Python package manager and run the notebook with jupyter notebook.

Upon the running Jupyter you will see the terminal will throw some http links. You can click or copy paste one in your browser which will open up the page below and see the data analysis folder we created. Launching an new notebook is as easy as clicking on “New”.

Splash screen for Jupyter

Using the previous example we ran in the “dry interpreter” we obtain the below:

So if you compare with the previous Terminal session you will notice a few things:

  • Jupyter is far more readable
  • You can go back, edit, add or delete cells
  • You can run a cell independently from the others.

It just makes for a far better interactive and prototyping experience.

But let’s say you don’t want to run a Linux container to get started. There are less involved ways to get you playing with Python and there I would point you towards Google colab. Who doesn’t own a Google account? The good thing about Google is that they give you access to free tools bundled up with your email account, stuff like:

  • Google drive. (Lets you store files in the cloud)
  • Google docs, sheets and slide. Provides you with an easy Microsoft office like environment for all your
  • DID YOU KNOW ABOUT GOOGLE COLAB? Yes? No? Look below.
Jupyter notebook running on Google Colab

How cool is that? No need to set up anything, you can even share notebooks with others or work collaboratively on them and the best part is: It’s all stored on your Google drive, so if you’re messy with your files, you know Google will always back them up!

3. Taking it further using Microsoft Visual Studio Code.

I have tried loads of code editors out there. EMACS, Vim, Sublime text, Atom… In my Programming journey I have tried to be as old school as can be. Yet couple weeks ago I stumbled on Visual Studio Code and was… convinced? What sold it to me was… the extensions. Let’s just sratch the surface together:

  • You can install the Jupyter extension and run jupyter notebook in Visual Studio Code. No need to interact with Jupyter in the web browser anymore (which make its easier to organise your files locally in project folders).
  • You can add the “Polyglot” extension and use “Jupyter like” notebooks for SQL, PowerShell, C# (and others).
  • You get access to both your WSL Linux containers file system AND Terminal FROM THE EDITOR.
  • Hum… You can have the EMACS Org mode plugin (Please don’t hit me!) to jot down your deepest thoughts or manage your to-do lists (I’m sure that’s going to piss some people off!).
Jupyter notebook running in Visual Studio Code

This was just a quick tour to get you started step by step and which will hopefully convice you to take the plunge and try out some scripting languages for yourself!

--

--