Articles about Python

Python Logo

Python is one of the most versatile programming languages in the world. With Python, you can control electronics, build web applications and perform machine learning.

In this page, you can find articles on Python references, coding and application setup.

How to setup Raspbian Stretch Lite on Raspberry Pi Zero W to run Python 3 applications

With Wi-Fi included, the Raspberry Pi Zero W is very useful for implementing embedded projects that require Internet connection.

Apart from using the Raspberry Pi Zero W for CCTV surveillance, we can run customized Python 3 applications on a Raspberry Pi Zero W for various use cases.

Pairing the official operating system for Raspberry Pi with Python 3, we will be able to get a versatile computer to do our bidding.

Anticipating the need to setup a version of Raspbian Lite on Raspberry Pi Zero W for future Python 3 projects, I created this post to document the steps of how to do so with Raspbian Stretch Lite.

How to setup Raspbian Jessie Lite on Raspberry Pi 3 to run Python 3 applications

The Raspbian operating system is the Raspberry Pi Foundation’s official supported operating system. As of this writing, Raspbian comes in two flavours – one with a graphical user interface for us to build a low cost desktop computer and the other without the graphical user interface.

If you intend to use your Raspberry Pi 3 with sensors and build a web interface for you to manage those sensors, Raspbian Jessie Lite is one operating system which you may want to install on your Raspberry Pi 3.

And with the versatility of Python 3, setting up Raspbian Jessie Lite on Raspberry Pi 3 to run Python 3 applications will be one of the first task that you will perform before you embark on your next sensor based project with the Raspberry Pi 3.

This post documents the steps that I took to setup Raspbian Jessie Lite on Raspberry Pi 3 to run Python 3 applications.

How to host your Python 3 Flask MVP with Supervisor on Ubuntu Server 16.04

Due to its minimalistic design, the Python Flask framework is ideal for building the web server layer of minimal viable products (MVP) to validate customers’ needs. However, development work is just one part of the user validation efforts. To ensure that our customer can access our Flask MVP and provide feedback as and when they are available, we will need to get it running with as a server daemon.

Supervisor is a convenient tool for running applications as a server daemon.

This post documents the steps that I took to host a Python 3 Flask MVP with Supervisor on an Ubuntu Server 16.04 instance.

How to setup Ubuntu Classic Server 16.04 on Raspberry Pi 3 for running Python 3 applications

Most of the customers who wanted to try out my minimal viable products (MVP) would provide me with an instance of Ubuntu Classic Server 16.0x these days. As such, it makes sense for me to trial my MVPs on the Ubuntu Classic Server 16.0x to ensure that I spend minimal time in deploying my MVPs to validate my customers’ needs. Since I have a few Raspberry Pi 3s lying around in the house, I can install a version of Ubuntu Classic Server 16.0x to serve as the development server for me to trial my MVPs.

Fortunately, the good folks at ubuntu-pi-flavour-maker.org had put up an optimised Ubuntu Classic Server 16.04 image for Raspberry Pi 3.

This post documents the steps that I took to run Ubuntu Classic Server 16.04 on my Raspberry Pi 3 for running Python 3 applications.

How to serve static files with Python 3 + Flask

Python Flask is a good microframework for building a minimal viable product to validate our ideas on the Internet. A modern web application encompasses documents that tell the web browser how to build the visuals of our web application and communicate with our server backend. Such documents are usually static in nature and are served as they are to the web browser without any processing from the server end.

Comparing setting up an instance of the Nginx server with adding code in our Flask application, the latter can be a more convenient way for us to realise our minimal viable product. This post documents the proof of concept that I did to serve static files with Python 3 and Flask.

A platform independent way to set your Python Path for your Python applications

In a software development house where desktop computers run Microsoft Windows while servers run Linux, software developers will have to ensure that the Python code that they wrote on their Windows machine can run on the deployment servers which are running Linux.

One unavoidable task for Python application developers is the importing of functionalities that are contained in other Python scripts. In order for the Python interpreter to find the Python scripts that are referenced by Python import statements, the Python Path will need to contain the URLs of the directories that contain the Python scripts to be imported.

How to sort a python dictionary by keys

I am a fan of hash tables when I need to implement logic that augments computation results to a common data structure that need to be used across several function bodies. The ability of the hash table in providing constant access by key helps me in keeping my logic from taking too much time to complete.

Python’s version of hash tables are known as a dictionaries or associative arrays. Apart from augmenting computation results to values of my Python dictionaries, one common task that I often perform is sorting the results by the dictionary keys. In this post, I document how I can sort my Python dictionary by its keys.

How to generate n-grams in Python without using any external libraries

There are many text analysis applications that utilize n-grams as a basis for building prediction models. The term “n-grams” refers to individual or group of words that appear consecutively in text documents.

In this post, I document the Python codes that I typically use to generate n-grams without depending on external python libraries.