Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions examples/A21_import_system/import_absolute.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions examples/A21_import_system/import_relative.py
Original file line number Diff line number Diff line change
@@ -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()