A popular and useful creational design pattern.

Builder pattern can be used when constructing complex objects, where it has several advantages:

  • It can divide the creation process into multiple steps, which can make the code clearer when constructing a complex object.
  • It allows different representations of an object to be…


Using Pysound

In this example, we will create a simple sine wave sound, using the Pysound library.

The code

Here is the code:

After importing several…


Photo by Hassan Pasha on Unsplash

Loosely coupled algorithm selection

Strategy pattern is a behavioural design pattern. It allows an object to choose between different strategies in a structured way.

A strategy might be an algorithm — for example, your code might need to apply various search algorithms to a data set. You might need to…


A singleton is an object for which there is only one instance in the entire system. Examples of potential singletons include:

  • A logging system. Various parts of the system might need to write log messages as the system executes. …


You aren't supposed to go onto stackoverflow and blindly cut and paste the first solution you find into your own code.

If you look at several related questions on stackoverflow, read the solutions and comments, then take the time to understand how they work, why upvoted solutions are good, and why the downvoted solutions are bad, you will learn a great deal.

It is a fantastic resource, if you are willing to put the effort in and use it as a learning tool.


Using the Pillow deform function

You can use the Pillow ImageOps deform function to apply general deformations to an image. Typical deformations include:

  • Barrel distortion. This happens when an image appears more magnified at its centre than its edges. It is sometimes called a fisheye effect.
  • Pincushion distortion, which is…


Stop wasting time trying to manually install those difficult modules.

Python is great, made better by the extensive infrastructure provided by open-source modules.

What isn’t always so great is installing all the modules you need, and making sure they are all mutually compatible with your version of Python and with…


In this article we will see how to create Voronoi diagrams in Python, using Scipy and generativepy.

What are Voronoi diagrams?

This image shows a set of seed points. We have placed the seed points randomly, but you could place the points according to some pattern if you prefer.


Catch errors and handle them in your app.

In this article we will look at exceptions:

  • Program errors.
  • What are exceptions?
  • Exceptions types.
  • Catching exceptions.
  • Using else with exceptions.
  • Using finally with exceptions.
  • Throwing exceptions.

This article is taken from my book Python Quick Start.

Program errors

Computer programs sometimes go wrong. There are three broad types of error you…


Optimize list and string manipulation using slice notation.

Slicing allows us to access part of a list or other sequence. In this article we will see how to:

  • Specify a slice of a list.
  • Use negative indices.
  • Delete or replace a slice of a list.
  • Take a slice of a tuple or string.
  • Loop over a slice.
  • Use…

Martin McBride

Software developer. Java, Python, C++ etc. I write for pythoninformer.com and maintain the generativepy library.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store