Prevent Import Errors in Python with __all__

Want to guarantee that no one can run "from .. import *" on your #Python module? Include a non-existent name in the __all__ list: x = 100 y = [10, 20, 30] __all__ = ['YOU_SHOULD_NOT_USE_IMPORT_*'] Using "from .. import *" on this module will result in an error!

  • No alternative text description for this image

Alternatively __all__ = [] will allow from module import * , but no names will be added to the global name space.

To view or add a comment, sign in

Explore content categories