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

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

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…

Alberto Gonzalez's avatar

Beautiful, Stephen.

Sovaks's avatar

The visual metaphor is so helpful!

Stephen Gruppetta's avatar

I love analogies and metaphors!