A couple of interesting capabilities in this post. The section "Controlling What Can Be Imported and What Not" is wrong or misleading though. The dunder __all__ only limits wildcard imports like `from my_module import * `. In your example both `foo` and `bar` can be imported/accessed like `from my_module import foo, bar` or `import my_module; my_module.foo(); my_module.bar()`.
Edit: Also just tried to `import * ` with `_all__ = []` and no AttributeError is raised as is stated. Python 3.7.4
Wow thank you very much MartinHeinz -- I've been using Python for years and the only two of these I knew were the __enter__ and comparator dunders! Saved, bookmarked, and shared with friends.
7 comments
[ 3.8 ms ] story [ 19.6 ms ] threadEdit: Also just tried to `import * ` with `_all__ = []` and no AttributeError is raised as is stated. Python 3.7.4
A general observation is that the itertools module is full interesting nuggets. I am always finding something new.