[Fixed] No module named ‘pytest’

Quick Fix: Python raises the ImportError: No module named ‘pytest’ when it cannot find the library pytest. The most frequent source of this error is that you haven’t installed pytest explicitly with pip install pytest. Alternatively, you may have different Python versions on your computer, and pytest is not installed for the particular version you’re … Read more

(Fixed) No Module Named ‘Pip’ Error

Quick Fix: Python raises the ImportError: No module named ‘pip’ when it cannot find the library pip. The most frequent source of this error is that you haven’t installed pip. Alternatively, you may have different Python versions on your computer, and pip is not installed for the particular version you’re using. I have compiled the … Read more

[FIXED] AttributeError: ‘NoneType’ object has no attribute ‘something’

Introduction Problem: How to solve “AttributeError: ‘NoneType’ object has no attribute ‘something’ “? An AttributeError is raised in Python when you attempt to call the attribute of an object whose type does not support the method. For example, attempting to utilize the append() method on a string returns an AttributeError as lists use the append() … Read more

[SOLVED] ValueError: invalid literal for int() with base 10

[toc] Introduction Problem: How to fix “ValueError: invalid literal for int() with base 10“? In Python, you can convert the values of one type into another. That means you can convert the integer strings into integers, integers into floats, floats into strings, etc. But one such conversion that Python dislikes is to change a float … Read more

[FIXED] TypeError: string indices must be integers

[toc] Problem Statement: Why am I seeing TypeError: string indices must be integers? Reason: This error generally occurs when you use a string value to access an iterable object. In other words, it indicates that we are trying to access the value rom the index of an iterable using a string index instead of using … Read more

How to Make Division by Zero to Zero in Python?

In Python, division by zero generates the exception ZeroDivisionError:  division by zero.  This is because in mathematics, division by zero is undefined. Today we’ll go over some ways to avoid the zero division error in Python and force it to return a zero. First, we’ll look into exception handling in Python. Second, we’ll examine different … Read more

No, Python __oct__() Doesn’t Exist Anymore. Do This Instead!

The Problem TypeError: ‘…’ object cannot be interpreted as an integer If you’re reading this article, chances are that you have been thinking something along those lines: Given a custom class My_Class. You want to override the behavior of the built-in oct(x) function in Python when calling it on a My_Class object x. You know … Read more

No, Python __hex__() Does Not Exist. Do This Instead!

The Problem TypeError: ‘…’ object cannot be interpreted as an integer If you’re reading this article, chances are that you have been thinking something along those lines: Given a custom class My_Class. You want to override the behavior of the built-in hex(x) function in Python when calling it on a My_Class object x. You know … Read more