Category Archives: Python 3

Intro to Black – The Uncompromising Python Code Formatter

There are several Python code checkers available. For example, a lot of developers enjoy using Pylint or Flake8 to check their code for errors. These tools use static code analysis to check your code for bugs or naming issues. Flake8 will also check your code to see if you are adhering to PEP8, Python’s style guide.

However there is a new tool that you can use called Black. Black is a Python code formatter. It will reformat your entire file in place according to the Black code style, which is pretty close to PEP8.


Installation

Installing Black is easy. You can just use pip for that:

pip install black

You can also configure popular text editors and IDEs to use Black following these instructions.

Now that Black is installed, let’s give it a try! Continue reading Intro to Black – The Uncompromising Python Code Formatter

Books on Sale for PyCon 2019

In honor of PyCon 2019 that is starting this week, I am putting three of my books on sale. You can get any of the following books for $9.99 through May 6th by clicking on the links:

Python 201 is a fun book for those of you who would be interested in learning intermediate and advanced topics in Python.

My ReportLab book covers how to create PDFs using Python and ReportLab. It also covers many other topics related to PDFs, such as splitting, merging and overlaying PDFs to name a few.

Finally my Jupyter Notebook 101 book is a good way for you to learn about the Jupyter Notebook and many of its capabilities.

wxPython 4 and PubSub

The Publish-Subscribe pattern is pretty common in computer science and very useful too. The wxPython GUI toolkit has had an implementation of it for a very long time in wx.lib.pubsub. This implementation is based on the PyPubSub package. While you could always download PyPubSub and use it directly instead, it was nice to be able to just run wxPython without an additional dependency.

However, as of wxPython 4.0.4, wx.lib.pubsub is now deprecated and will be removed in a future version of wxPython. So now you will need to download PyPubSub or PyDispatcher if you want to use the Publish-Subscribe pattern easily in wxPython.


Installing PyPubSub

You can install PyPubSub using pip.

Here’s how to do it:

pip install pypubsub

PyPubSub should install quite quickly. Once it’s done, let’s find out how to use it! Continue reading wxPython 4 and PubSub

Face Detection Using Python and OpenCV

Machine Learning, artificial intelligence and face recognition are big topics right now. So I thought it would be fun to see how easy it is to use Python to detect faces in photos. This article will focus on just detecting faces, not face recognition which is actually assigning a name to a face. The most popular and probably the simplest way to detect faces using Python is by using the OpenCV package. OpenCV is a computer vision library that’s written in C++ and had Python bindings. It can be kind of complicated to install depending on which OS you are using, but for the most part you can just use pip:

pip install opencv-python

I have had issues with OpenCV on older versions of Linux where I just can’t get the newest version to install correctly. But this works fine on Windows and seems to work okay for the latest versions of Linux right now. For this article, I am using the 3.4.2 version of OpenCV’s Python bindings. Continue reading Face Detection Using Python and OpenCV