Articles tagged with "python3"
ImageMagick: convert vs Wand
The ImageMagick suite has been in my software toolbox for years. It is my go-to tool for manipulating bitmap images. Over the years I have written several front-ends for specific tasks for in Python.
In general, I have used the subprocess module to launch
convert
ormogrify
from Python.With the release of Wand 0.5.0 which supports ImageMagick 7, I decided to try that by porting one of my scripts (foto4lb) to it. This turned out to be slower than using
convert
directly.But now it is 2021. Py-wand is at 0.6.7 and it is time to try again.
Installing Pelican 4
Pelican is the static site generator that I use for my website. This allows me to write my website posts in almost plain text (actually a light-weight markup language named reStructuredText), which are then translated into HTML. As someone who has written his webpages in HTML by hand, I can tell you that this is definitely an improvement.
Although I use LaTeX for things that require high-quality typesetting, these days almost all my other writings are in reStructuredText.
The previous pelican version 3.7 was basically the last Python 2.7 application that I use. So now that pelican supports Python 3, I’m switching. Since Pelican 4 is not in the FreeBSD ports tree yet, I’m installing it myself.
Note
As of 4.0.1, Pelican is now in the FreeBSD ports tree and I’m using the port
www/py-pelican
. At the moment I’m still installingtypogrify
andsmartypants
by hand.Using the FT232 with Python
In this article I will try to document how to with with the FT232H using Python on FreeBSD. I will be using the Adafruit FT232H breakout board.
Note that since I’m using FreeBSD, the library provided by FTDI doesn’t work. However, the library provided by Adafruit was written for Python 2, and doesn’t work with Python 3. I tried tinkering with it a bit to get it to work with Python 3, but that did not work out. In the end, I went with pyftdi since it doesn’t require a native library and it just works.
Measuring particulate matter with the PMS5003
This article details how I used the Plantower PMS5003 particulate matter (“PM”) sensor on a PC or laptop, using an FT232H breakout board to make the connection.
Install ntpsec on FreeBSD
Using sqlite3 for time management
After some initial experiments with sqlite as a replacement for a json data file format (which I did not pursue in the end), I have now started using sqlite in earnest. And I must say that I quite like it.
Database scheme for resin recipes
This document explores how an SQLite database could be used to store data for the resin-calculator. Normally, the recipes are a dictionary keyed to the name of the resin. The value of each recipe is a list of (component, parts-by-weight) tuples. Since a database only contains tables, where each row has the same form, how do we store such infomation in a database?
Doing calculations with Python
As an engineer I do a lot of calculations. These can be done with pen and paper and a calculator, in an IPython notebook or in a throwaway spreadsheet. All of these methods have shortcomings, though.
Pen and paper is hard to share and (in my case) hard for others to read. In IPython you can assign the results of calculations to a variable, but you have to perform a separate action to display them. And spreadsheets in general show you the results but not the calculations.
So I wrote a simple function in Python to help me with that. Using this function I can print both simple assignments and relatively complex calculations. And it shows both the calculation and the result.
Improving my Python coding
With leading white space governing the indentation level and so the grouping of statements, Python code already looks relatively clean.
Yet there are additional tools that will help you improve your code.