When I was studying python before, I mentioned __all__
, but I'm starting to wonder what it is recently, so I'll make a note of it.
__all__
is what you write in the __init__.py
file. So all the strings you write in all will be imported when this python module is imported.
So, with from package import *
, the function of the previous string in this package will be imported. Other than that, it will not be imported.
It was that. that's all
By the way, from package import *
is a very disliked writing style, so be careful not to use it as much as possible.
The following is the answer when asked by the overseas community that I referred to. The outline is written above, so please have a look if you are interested.
__all__
is a variable that can be set in the__init__.py
file of a package.
The
__all__
variable is a list of strings which defines those symbols that are imported when a program does
from package import * If the
__all__
for this package was set as follows:
all = ['echo', 'effect', 'reverb']
then
from package import *
would be equivalent to
from package import echo from package import effect from package import reverb
Note that using
from <package> import *
is considered bad style in production code, since you have no control over what >you are importing and what your import might shadow.
for more information see : 6. Modules - Python 3.8.2 documentation
Recommended Posts