Optional and Local Imports
Let's learn about optional and local imports and how it works.
We'll cover the following
Optional imports
Optional imports are used when we have a preferred module
or package
that we want to use, but we also want a fallback in case it doesn’t
exist. For example, we might use optional imports to support multiple versions of software or for speed ups.
Examples of optional import
Here’s an example from the package github2
that demonstrates how we might use optional imports to support different versions of Python:
Get hands-on with 1400+ tech skills courses.