Rafal Jasionowski

Python Import Error (ModuleNotFoundError)

Python’s ImportError (ModuleNotFoundError) indicates that you tried to import a module that Python doesn’t find. It can usually be eliminated by adding a file named __init__.py to the directory and then adding this directory to $PYTHONPATH. If this file (__init__.py) is in the folder, change the position of the import in the file that is …

Python Import Error (ModuleNotFoundError) Read More »

How to Fix “ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()”

If you run the following code, you’ll experience a special ValueError: The output will be this error message: Try It Yourself in our interactive browser shell: Solution: Using the Numpy functions called logical_and() and logical_or() instead of Python’s logical operators (“and” and “or”) is the solution. Why does the ValueError occur at all? Many programmers …

How to Fix “ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()” Read More »

How to Access an Object Attribute Given the Attribute Name as a String?

You may know the following problem: You have an object’s attribute name as a string—say, you’ve read it from a file—and you want to access the attribute with the given name. But you cannot use the syntax object.”attribute” because the dot notation only allows for name-access like this: object.attribute. How do you resolve this problem? …

How to Access an Object Attribute Given the Attribute Name as a String? Read More »

How to resolve “TypeError: can only concatenate str (not “int”) to str” in Python?

Many beginner programmers have a problem with the so-called TypeError, they wonder what they are doing wrong. Here’s an example: Exercise: Run the script and reproduce the error! Study this article to learn how to fix it! This article will answer every question that beginners may ask about this topic. About The TypeError Before showing …

How to resolve “TypeError: can only concatenate str (not “int”) to str” in Python? Read More »