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

How to Disable Unit Tests Temporarily in Python?

Problem Formulation Say, you’ve written a number of unit tests using the unittest module in Pyhton. How can you disable specific unit tests temporarily? In other words: How to skip a unit test in Python’s unittest module? Example: Given the following three unit tests. How to disable tests 1 and 2? Method 1: Skip Test … Read more

Difference Between exit() and sys.exit() in Python

Problem: There are two similarly-named functions in Python, exit() and sys.exit(). What’s the difference between them, and when should I use one over the other? Introduction In contrast to programming languages like C, there is no main() method in Python. Thus, when we run a program in Python, we essentially execute all the code in the top-level file, … Read more

How to Detect Lowercase Letters in Python?

Problem Formulation Given a string s. How to get a Boolean value that indicates whether all characters in the string are lowercase? Example: Say, you ask the user for input and you want to check whether all input characters are lowercase for further processing: If the user types in ‘alice’, the function should return True … Read more

Python OpenCV Image Processing – Resize, Blend, Blur, Threshold, Convert

This tutorial is an introduction to the OpenCV library. Learn how to convert color channels, resize, blend, blur, and threshold images in Python. The OpenCV [1] library contains most of the functions we need for working with images. Handling images in programming requires a different intuition than handling text data. An image is made up … Read more

Python random.seed() -A Deep Dive

Introduction random is an in-built module in Python which generates pseudo-random numbers. Now, the random data generated by this module is not completely random. Instead it is pseudo-random, as mentioned previously. ? Note: A “True Random Number” can be generated by a TRNG (true random number generator) while a “pseudo-random number” is generated by a … Read more