can someone please tell me what the differnce between using these two in my __init__.py
in my package? And which is better to use?
__all__ = ['functions']
from functions import *
can someone please tell me what the differnce between using these two in my __init__.py
in my package? And which is better to use?
__all__ = ['functions']
from functions import *
The difference between the possible two statements in the script bar__init__.py is what scope the sub-packages or modules under bar are imported into. If the package bar contains the sub-package named functions, the statement
from functions import *
in bar__init__.py will import the functions sub-package into the scope of the bar package, and it can be accessed using the reference
bar.functions
in Python code that imports bar. If bar__init__.py contains the code
all = [functions]
then Python code containing the code
from bar import *
will define the sub-package as functions (with no reference to bar.)
Either method can be used to reference the contents of the sub-package functions, but the syntax is different.
print(len(globals()))
import sys
print(len(globals()))
from sys import *
print(len(globals()))
OUTPUT:
8
9
67