A short, visual tour of different ways of using Python's `import`
Nice! What would this analogy look like for import some_module.other_module?
Right—first usual caveat about analogies—at some point they fail! In this case, Python's `import` doesn't quite do what many expect since the parent module is still loaded.
For example:
```python
>>> import collections.abc
>>> values = collections.deque([2, 4, 6])
>>> values
deque([2, 4, 6])
```
Note how I imported `collections.abc` but then I could still access `collections.deque`! So in this case, the whole box is placed on the shelf anyway!
However, in some modules, submodules aren't imported by default, so need to be explicitly imported. This is where the analogy fails…
Beautiful, Stephen.
Thanks Alberto!
The visual metaphor is so helpful!
I love analogies and metaphors!
Nice! What would this analogy look like for import some_module.other_module?
Right—first usual caveat about analogies—at some point they fail! In this case, Python's `import` doesn't quite do what many expect since the parent module is still loaded.
For example:
```python
>>> import collections.abc
>>> values = collections.deque([2, 4, 6])
>>> values
deque([2, 4, 6])
```
Note how I imported `collections.abc` but then I could still access `collections.deque`! So in this case, the whole box is placed on the shelf anyway!
However, in some modules, submodules aren't imported by default, so need to be explicitly imported. This is where the analogy fails…
Beautiful, Stephen.
Thanks Alberto!
The visual metaphor is so helpful!
I love analogies and metaphors!