6 Comments
User's avatar
Petr Pošík's avatar

Nice! What would this analogy look like for import some_module.other_module?

Expand full comment
Stephen Gruppetta's avatar

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…

Expand full comment
Alberto Gonzalez's avatar

Beautiful, Stephen.

Expand full comment
Stephen Gruppetta's avatar

Thanks Alberto!

Expand full comment
Sovaks's avatar

The visual metaphor is so helpful!

Expand full comment
Stephen Gruppetta's avatar

I love analogies and metaphors!

Expand full comment