## How to Convert Hex String to Integer in Python

Problem Formulation Given a string in hexadecimal form: How to convert the hex string to an integer in Python? For example, you want to convert the hexadecimal string ‘0xff’ to the decimal integer 255. Here are a few other examples: 0x0 –> 0 0x4 –> 4 0x8 –> 8 0x12 –> 18 0x16 –> 22 … Read more

## [Solved] TypeError: ‘int’ Object Is Not Subscriptable in Python

To fi TypeError: object is not subscriptable if you try to use indexing upon an object that is not subscriptable. To fix it you can:

## [Solved] NumPy RuntimeWarning: All-NaN slice encountered

Problem Formulation You use NumPy’s np.nanmedian() function in your code that is supposed to ignore NaN values when computing the mean of a NumPy array. But when using it, NumPy raises a RuntimeWarning: All-NaN slice encountered message: What is the reason for this warning and how to fix it? Solution + Explanation The reason this … Read more

## [Solved] NumPy RuntimeWarning: Mean of empty slice

Problem Formulation You use NumPy’s np.nanmean() function in your code that is supposed to ignore NaN values when computing the mean of a NumPy array. But when using it, NumPy raises a RuntimeWarning: Mean of empty slice message: What is the reason for this warning and how to fix it? Solution + Explanation The reason … Read more

## How to Display, Modify and Save Images in Matplotlib

This article will show you how to visualize, modify and save images in Python, more specifically in Matplotlib. In the following sections, we will see how to load images, how to modify some of their properties and finally how to save them. Long story short If you want to import an image and to display … Read more

## A Simple Introduction to Set Comprehension in Python

Being hated by newbies, experienced Python coders can’t live without this awesome Python feature. In this article, I give you everything you need to know about set comprehensions using the bracket notation {}. What is Set Comprehension? Set comprehension is a concise way of creating sets in Python using the curly braces notation {expression for … Read more

## How to Get an HTML Page from a URL in Python?

This tutorial shows you how to perform simple HTTP get requests to get an HTML page from a given URL in Python! Problem Formulation Given a URL as a string. How to extract the HTML from the given URL and store the result in a Python string variable? Example: Say, you want to accomplish the … Read more

## How to Create Alexa Skills in Python? A Simple Overview for Beginners

Alexa is on the way to lead the next wave of technological disruption. Have you ever asked yourself about the exact steps needed to create an Alexa Skill? And how these steps interplay with each other? To answer these questions, I give you a quick overview of Alexa Skill development in Python. This article serves … Read more

## How to Crop an Image Using PIL?

Problem Formulation Given an image stored at image.jpeg, a target width and height in pixels, and a target starting point (upper-left) x and y in the coordinate system. How to crop the given image in Python PIL so that the resulting image has width * height size? Here’s an example of how the original image … Read more

## How to Print the Content of a .txt File in Python?

Problem Formulation Given the path to a text file such as /path/to/file.txt. How to read all the content from the file and print it to the Python standard output? Standard File Reading and Printing The standard approach to read the contents from a file and print them to the standard output works in four steps: … Read more

## How to Split a List Into Evenly-Sized Chunks?

In this article, you’ll learn how to divide a list into equally-sized chunks in Python. Step-by-step, you’ll arrive at the following code to chunk your list into evenly-sized parts: Go ahead and play around with the code yourself but if you need some explanations, read on because I’ll explain it to you in much detail: … Read more

## IndentationError: Unindent Does Not Match Any Outer Indentation Level

Summary: The error IndentationError: unindent does not match any outer indentation level arises if you use inconsistent indentation of tabs or whitespaces for indented code blocks such as the if block and the for loop. For example, Python will throw an indentation error, if you use a for loop with four whitespace characters indentation for the first line, and one tab character indentation of the second line … Read more