Import Pitfalls
Understand the common import pitfalls in Python such as circular imports and shadowed imports that lead to errors. Learn to identify these problems through examples and explore strategies like code refactoring to avoid them, enhancing your module management skills.
We'll cover the following...
We'll cover the following...
Common import pitfalls
There are some very common import pitfalls that programmers fall into. We’ll go over the two most common here:
- Circular imports
- Shadowed imports
Let’s start by looking at circular imports.
Circular imports
Circular imports happen when we create two modules that import each other.
Let’s look at an example as that will make it quite clear what
we are referring to.
Put the following code into a module called
a.py.
...