Advanced logging features in Python using the standard logging module

Image for post
Image for post
Watching and filtering logging messages, photo by Soumil Kumar from Pexels

I work as a software developer for a company that develops climate control systems for greenhouses. These climate control systems control various aspects of a greenhouse to create an optimal climate for growing crops. We connect the system to several sensors, and the system sends the measurements of these sensors to a central location in the cloud.

The grower, our customer, can access these measurements through various dashboards that include graphs and reports. Last week, we received a customer call through the helpdesk that he did not see any new measurements come in. …

Use a Convolution Deep Neural Network to enter Kaggle’s Dogs vs Cats competition

Image for post
Image for post
Image by Snapwire from Pexels

I like to use practical examples and projects to help me memorize the theory during my study of Deep Neural Networks. An excellent resource for finding these practical projects is Kaggle. Kaggle is an online community of data scientists and machine learning practitioners.

Kaggle allows you to search and publish data sets, explore, and build models. You can perform these functions in a web-based environment. Kaggle also offers machine learning competitions with actual problems and provides prizes to the winners.

I am currently studying Deep Learning with TensorFlow. One of the subjects I want to learn is image recognition. This article describes my attempt to solve a former Kaggle competition from 2013, called “Dogs vs. Cats.” For implementing the solution I used Python 3.8 …

My first exploration of Machine learning using the Titanic competition on Kaggle

Image for post
Image for post
Louis & Lola, survivors of the Titanic disaster (Photo from Library of Congress Prints and Photographs, No known restrictions on publication)

This article describes my attempt at the Titanic Machine Learning competition on Kaggle. I have been trying to study Machine Learning but never got as far as being able to solve real-world problems. But after I read two newly released books about practical AI, I was confident enough to enter the Titanic competition.

The first part of the article describes preparing the data. The second part shows how I used a Support Vector Machine (SVM). I used the SVM to create a model that predicts the survival of the passengers of the Titanic.

The model resulted in a score of 0.779907, which got me in the top 28% of the competition. I am very happy with the result. You can find a Jupiter notebook with the solution and documentation in Github. …

Investigate health inspection results for New York City’s 27,000 restaurants using Python

Image for post
Image for post
Ruebens Style Pastrami, image by the author

A week ago, I saw a tweet from Ashley Willis (@ashleymcnamara) in which she asked, “What’s the best tech talk you’ve ever seen?”. The response was overwhelming. Make sure to check out the answers for some of the most excellent tech talks.

Since then, I have been watching some of the recommended talks. The first I saw was “Discovering Python” by David Beazley. An exceptional talk in which he uses Python to support a Patent litigation lawsuit.

As I searched for more talks by David Beazley, I found “Builtin Superheroes.” In this presentation, he used standard Python data types to analyze food inspections. …

Quickly create a list, dictionary, or set in Python without using for loops

Image for post
Image for post
A comprehensive set of turnstones, image by the author

Python offers three types of comprehensions to create basic collection data types conveniently in Python with better readability.

I will explain each type of comprehension using examples.

List Comprehensions

List Comprehensions are a different way of rapidly creating a list with Python. If you find yourself using a for loop along with .append() to create a list, List Comprehensions are an excellent alternative.

List Comprehensions have the following signature.

[expr for val in collection if condition]

You can use List Comprehensions for the following:

  • Manipulating lists
  • Extracting information
  • Filtering lists

I will explain the possibilities of List Comprehensions using four different examples. Each example shows how to implement the functionality with and without List Comprehensions. …

Feedback can be difficult. Here’s a recipe for your pull requests

Image for post
Image for post
Pull Request comments on GitHub (Image by the author)

Almost twenty years ago, I started as a developer in a company that used code reviews. At that time, I had never done a code review nor was my code ever reviewed.

For my first project, I had to create a COM component in C++ using the ATL framework. ATL uses reference counting to manage the lifetime of an object. Reference counting means that you have to call Release() when you are done using the object. If you forget to call it, it results in a memory leak.

I remember the result of my first code review as if it was yesterday. …

Handle your errors in Python like a pro

Image for post
Image for post
Error handling in Python, image by the author

When during the execution of a program, Python encounters an error, it stops. This can be caused by two types of errors, syntax errors, or exceptions. In this article, we will discuss the second, exceptions, and show how to handle, catch, and raise them.

What are Exceptions?

Exceptions are errors that Python reports when syntactically correct code executes, and an exceptional situation occurs. For example, look at the following code.

A program that raises an exception

This program tries to divide the number ten by zero, which is something that is not possible in Python.

When you execute this program, Python raises a ZeroDivisionError and terminates the application. …

How to log message in Python using the standard logging module

Image for post
Image for post
Photo by Chris Ried on Unsplash

The standard library with each Python installation contains a logging module that provides a flexible framework for logging messages. Most Python applications and libraries use this module.

There are four types of classes used when logging.

  • Loggers — exposes the interface that your application can use to log
  • Handlers — send the log messages to the appropriate destination
  • Filters — determine which messages is send to what output
  • Formatters — how is a message formatted in the final output


To create a logger in your application or library, you can call logging.getLogger("app"). The argument "app" is the name that you choose for this logger. You can use the name of a logger to form a hierarchy by using dots in the name like 'app.module.function'. A Filter can use this hierarchy to only view messages from a specific function or module. …

Verify that your Python code works how it should

Image for post
Image for post
Unit tests in Python, image by the author

Every year I try to learn a new programming language. This year I started learning Python.

During my day job, I work as a professional programmer. I use C++, C#, and Javascript. I am part of a development team that uses unit testing to verify if our code works how it should.

In this article, I investigate how to create unit tests with Python by discussing the following topics.

  • Unit testing fundamentals
  • Available Python testing frameworks
  • Test Design principle
  • Test Doubles
  • Code Coverage

To be able to follow along with this article, I assume that you have a basic understanding of Python. …

Using Node.js, Botkit, Botkit CMS, and LUIS to build a Slack bot

Image for post
Image for post
Screenshot from the movie WarGames (1983)

Ever since I heard the computer W.O.P.R. ask Matthew Broderick if he wants to play a game, I have been fascinated by talking to computers. W.O.P.R. was the United States military supercomputer from the movie Wargames.

I remember trying to create a program in BASIC on my Commodore 64. This program simulated W.O.P.R. It read a string from the command-line and generated a response in the text on the screen. I was as proud as a peacock.

Fast forward almost 40 years. Currently, it has never been easier to develop an application that lets you talk to your computer.

In this article, I’ll explain how to create an advanced Slack Bot in Node.js with Botkit, Botkit C.M.S., and L.U.I.S. …


Patrick Kalkman

I write and design software. I love to learn and teach. I am an Open-Source and Agile enthusiast.

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