Reputation: 1207
I would like to know the purpose of a three-dots symbol aka ellipsis put before the package name in an import statement.
Examples:
sklearn/metrics/_plot/det_curve.py:
import scipy as sp
from .base import _get_response
from .. import det_curve
from .._base import _check_pos_label_consistency
from ...utils import check_matplotlib_support
or this Github issue, where they call it an "ellipsis import" and where the three dots are followed by a space:
from ... import MyContentContentType as __MyContentContentType__
from ... import MyDetectionDetectionGender as __MyDetectionDetectionGender__
Upvotes: 2
Views: 525
Reputation: 1207
../..
in shell):When specifying what module to import you do not have to specify the absolute name of the module. When a module or package is contained within another package it is possible to make a relative import within the same top package without having to mention the package name. By using leading dots in the specified module or package after
from
you can specify how high to traverse up the current package hierarchy without specifying exact names. One leading dot means the current package where the module making the import exists. Two dots means up one package level. Three dots is up two levels, etc. So if you executefrom . import mod
from a module in thepkg
package then you will end up importingpkg.mod
. If you executefrom ..subpkg2 import mod
from withinpkg.subpkg1
you will importpkg.subpkg2.mod
. The specification for relative imports is contained in the Package Relative Imports section.
Upvotes: 3