__all__ Explained

Tagged: ,

This topic was published by and viewed 696 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author
    Posts
  • DevynCJohnson
    DevynCJohnson
    Keymaster
    • Topics - 444
    • @devyncjohnson

    In Python, "__all__" is a special variable that is commonly used in libraries.
    "__all__" should be near the top of  a script before any imports are performed and before defining any classes, variables, or functions. When the library is imported, "__all__" acts like an index of importable objects within the library. In other words, this variable lists public objects. So, running "from LIBRARY import *" will only import the objects listed in the "__all__" variable.

    __all__ = [
    'FUNCTION1',
    'FUNCTION2',
    'FUNCTION3',
    ]

    See http://dcjtech.info/topic/pybooster/ which is a collection of Python libraries that use "__all__".

    Further Reading

Viewing 1 post (of 1 total)