A popular and useful creational design pattern.
Builder pattern can be used when constructing complex objects, where it has several advantages:
In this example, we will create a simple sine wave sound, using the Pysound library.
Here is the code:
from pysound.buffer import BufferParams
from pysound.oscillators import sine_wave
from pysound import soundfile
from pysound.graphs import Plotter
params = BufferParams()
out = sine_wave(params, frequency=500)
soundfile.save(params, 'sine-500.wav', out)
After importing several…
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…
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:
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.
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.
In this article we will look at exceptions:
This article is taken from my book Python Quick Start.
Computer programs sometimes go wrong. There are three broad types of error you…
Slicing allows us to access part of a list or other sequence. In this article we will see how to: