Save yourself hours of debugging by avoiding these common gotchas and pitfalls in your Python code

Regardless of which programming language you’re coding in, you’ve probably encountered good chunk of weird and seemingly unexplainable issues that ended up being really stupid mistakes or quirks of that specific language. Python aims at being clean and simple language, yet it also has its portion of gotchas and quirks that can surprise both beginner and experienced software developers. So, to avoid unnecessary rage and frustration over some weird issue in your favourite programming language, here follows a list of common Python pitfalls, that you should try to avoid at all costs.

Image for post
Image for post
Photo by Meor Mohamad on Unsplash

Mutable Default Arguments Are a Bad Idea

Setting default arguments for a function is very common and useful for defining optional arguments or arguments that can usually use same, predefined value. Setting default argument to a mutable value such as list or dict can, however, cause unexpected…

Hands-on Tutorials

Let’s get curated data, natural language processing, text-to-speech, plot rendering and more from Wolfram Alpha into your next project!

Anybody who at some point struggled with math knows Wolfram Alpha and was probably saved by its ability to solve any equation, plot any function or visualize logic circuits. Wolfram Alpha can; however, do much more than that, including chemistry, linguistics or history and most importantly — it can give you all the answers using its public API. So, in this article we will explore how you can use it to answer simple questions, solve mathematical problems, render plots or even describe DNA sequences!

Image for post
Image for post
Photo by vnwayne fan on Unsplash

Setting Up

Wolfram Alpha API is free (for non-commercial usage), but we still need to get API key (AppID) to perform queries against the API endpoints. To get API key we will first create Wolfram ID at When account is created we can navigate to, click on the Sign up to get your first AppID button, fill out Get a New AppID dialog. After that we will be presented with API key which is called AppID here, which we can test out with following sample…


Docker is not the only containerization tool out there and there might just be better alternatives…

In the ancient times of containers (really more like 4 years ago) Docker was the only player in the container game. That’s not the case anymore though and Docker is not the only, but rather just another container engine on the landscape. Docker allows us to build, run, pull, push or inspect container images, but for each of these tasks there are other alternative tools, which might just do better job at it than Docker. So, let’s explore the landscape and (just maybe) uninstall and forget about Docker altogether…

Image for post
Image for post
Photo by Nicole Chen on Unsplash

Why Not Use Docker, Though?

If you’ve been a docker user for long time, I think it will take some persuading for you to even consider to switch to different tooling. …

Getting Started

Recipes for using and creating awesome Python context managers, that will make your code more readable, reliable and less error prone…

Resource management is one of those things you need to do in any programming language. Whether you are dealing with locks, files, sessions or database connections — you always have to make sure you close and free up these resources for them operate correctly. Usually, one would do that using try/finally - using the resource in try block and disposing of it in finally block. In Python however, there is a better way - the context management protocol implemented using with statement.

So, in this article we will explore what it is, how it works and most importantly where you can find and how you can implement your own awesome context managers! …

Be a more productive web developer with these few Chrome DevTools tips and tricks.

If you’re a web developer, then you surely spend quite some time poking around in browsers dev tools or web console. Inspecting elements, modifying CSS or running commands in console — these are some basic things that every web developer knows how to do using browsers developer tools. There are however, quite a few more things you can do inside your browser to make your debugging, development and web design so much more efficient. Here are a few hidden or lesser known features of Chrome DevTools which you should know about and which you will be using every day…

Image for post
Image for post
Photo by Paweł Czerwiński on Unsplash

Pretty-Print Array as Table

When working with lots of data in JavaScript (e.g. creating data visualizations), things never work on first try and you will inevitably have to go to web console and view the data — probably with console.log. That will yield JavaScript Object (JSON), which in case of 2D arrays is going to be hard read and hard to find useful information in. But there's simple fix for…

Idioms and conventions that will make your Python code readable, effective, concise and reliable.

There are lots of ways one can implement same feature, algorithm or function. Some of them straightforward, clear — better, some of them confusing, inefficient — worse. The Python community often uses terms like Pythonic or when describing code that follows certain (natural, proper) style and conventions. That’s the kind of good, clear code we all try to write everyday and in this article we will go over a few tips, conventions and idioms that will help you write a bit more idiomatic and Pythonic code.

Image for post
Image for post
Photo by Ahmad Kadhim on Unsplash

Identity and Equality Comparisons

Not just in Python, but really in any programming language, you can fall into the trap of mixing up identity and value equality. In Python you have choice of using either is or == for comparisons, where is checks identity and == checks value. …

Let’s explore New York Times, The Guardian, HackerNews and other APIs and gather some news data for your next project!

Whether you are data scientist, programmer or AI specialist, you surely can put huge number of news articles to some good use. Getting those articles can be challenging though as you will have to go through quite a few hoops to get to the actual data — finding the right news sources, exploring their APIs, figuring out how to authenticate against them and finally scraping the data. That’s a lot of work and no fun.

So, to save you some time and get you started, here’s list of public news APIs that I was able to find, with explanation how authenticate against them, query them and most importantly examples for how to get all the data you need from them! …

Epidemics and Pandemics are still a hot topic so let’s visualize their history using interactive horizontal bar chart and D3.js!

COVID-19 is the current flavour of the month for data visualizations and everybody just wants to use this one dataset. In this article, however, we will take a step back for a second and take a look at the bigger picture — the whole history of worlds epidemics and pandemics. To do so, we will use a single interactive chart called the horizontal bar chart.

Image for post
Image for post
Chart Demo

The full chart can be found at It contains a list of almost 250 epidemics that happened between 1200 BC and 2020. Each bar represents one epidemic. …

Show off your projects and skills on GitHub with its hidden new feature — GitHub Profile READMEs!

If you visit other peoples GitHub profiles from time to time, you might have noticed recently, that some people have some fancy pictures, descriptions dn stats in their profiles. These are the new GitHub Profile README s. They are kind of a hidden new feature and in this article I will show you how to create one and how make it stand out using some cool tricks and tools!

Image for post
Image for post
GitHub Profile README

How to Create Your Own

Creating GitHub Profile README is very simple, but you probably would not find it on your own. To create it, go to same as when you want to create normal repository. Name the repository with you username - in my case that would be MartinHeinz/MartinHeinz. …

Working with SQL in Python can be easy with SQLAlchemy and its hybrid properties, nested queries, table metadata, dialects and more!

If you are Python developer and you work with SQL databases, then SQLAlchemy is most likely a library you are familiar with. It’s a powerful, yet flexible toolkit for working with SQL in Python with lots of features. Some of these features like ORM and basic queries are common knowledge, but there are quite a few features you might not know about and should definitely be taking advantage of. So, let’s se how to leverage things like hybrid properties, nested queries, table metadata, dialects and more!

Image for post
Image for post
Original Photo by Simone Viani on Unsplash

Column Properties

Let’s start simple. I think it’s pretty common that you might want to create mapped attribute based on other columns — essentially creating computed column. …


Martin Heinz

Certified Red Hat Professional | DevOps Engineer at IBM | Working with Python, JavaScript, Kubernetes, OpenShift, Docker and more |

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