In Python Programming, we can make use of relative imports to import packages or modules that are located either in the same package or subpackage of the current module.
Let's take a look at a few examples.
Example 1: Import a module from the same package:
from . import my_module
Example 2: Import from a sibling package:
from ..my_package2 import my_package2
Example 3: Importing a module from a subpackage:
from .subpackage2 import submodule2
Example 4: Import a module from a parent package:
from ..parent_module import parent_function
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!