DEV Community

tp1050
tp1050

Posted on

What does __all__ mean in Python?

1) Stackoverflow just makes it more complicated to understand something that is complicated
2) Python docs and people working in/on/at it love to talk as if they are wizards from the lord of rings or some other obscure place.

So WTF is all and why should/would you put it in the init of a package/module?

Most people who MADE/MAKE python come from C/C++ as all human beings must, so they need and crave a way of exerting control over how objects and data are accessed, that is more pronounced because well python has literally no controls in place everything is everywhere all the time and can be accessed by everyone.

So what do they do? all is realization of that fetish for control over data. When you put all at the top of a file, then you are sure excuting from module import * only and only imports those things you put in the all array at the top of the file. So in reality all is a shorthand for making sure with one tiny line of code you are importing only and exactly a few line of code.

If you asked me I think it is useless and mostly cyber-erotic manner of coding which is contagious btw.

if module: a.py -->

`all = ['bar', 'baz']

waz = 5
bar = 10
def baz(): return 'baz'`

then when you do
import from a *

you effectively get bar and baz but not waz.

Thats all.

If you got here because in the middle of an amazing hacking session you came across this yet an other weirdness of python and went down rabbit holes to understand its value, PLEASE STOP, go get an ice creme, chat up a girl/boy, take a deep breath and just let go......

Top comments (0)