From dc3330aedf2e1f0f23a51a37ae6676723424d49c Mon Sep 17 00:00:00 2001 From: Branimir Georgiev <66906831+braboj@users.noreply.github.com> Date: Thu, 19 Jun 2025 17:02:42 +0300 Subject: [PATCH] Fix future import placement --- README.md | 6 ++++++ examples/A21_import_system/import_absolute.py | 5 ++--- examples/A21_import_system/import_relative.py | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 examples/A21_import_system/import_relative.py diff --git a/README.md b/README.md index d660aaf..f324a53 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,12 @@ You can also run the examples from the command line. For example, to run the python examples/A01_introduction/hello_world.py ``` +To see how relative imports work within packages, run the `import_relative.py` example using the `-m` flag: + +```bash +python -m examples.A21_import_system.import_relative +``` + ## License diff --git a/examples/A21_import_system/import_absolute.py b/examples/A21_import_system/import_absolute.py index da803ba..9e10644 100644 --- a/examples/A21_import_system/import_absolute.py +++ b/examples/A21_import_system/import_absolute.py @@ -1,12 +1,11 @@ # Shows how to enforce and use absolute imports. # ------------------------------------------------------------------------------ # Example script demonstrating absolute imports. +from __future__ import absolute_import + # Using absolute imports import asyncio -# Enforce absolute imports -from __future__ import absolute_import - # Absolute imports from foo.api.submodule1 import func1 from foo.core.submodule2 import func2 diff --git a/examples/A21_import_system/import_relative.py b/examples/A21_import_system/import_relative.py new file mode 100644 index 0000000..e773c21 --- /dev/null +++ b/examples/A21_import_system/import_relative.py @@ -0,0 +1,11 @@ +# Shows how to use relative imports within a package. +# ------------------------------------------------------------------------------ +# Demonstrates importing modules from the current package using relative syntax. + +from .foo.api.submodule1 import func1 +from .foo.core.submodule2 import func2 +# Relative imports are scoped to packages. + +# Call the imported functions +func1() +func2()