What does a . in an import statement in Python mean?

PythonModule

Python Problem Overview


I'm looking over the code for Python's multiprocessing module, and it contains this line:

from ._multiprocessing import win32, Connection, PipeConnection

instead of

from _multiprocessing import win32, Connection, PipeConnection

the subtle difference being the period before _multiprocessing. What does that mean? Why the period?

Python Solutions


Solution 1 - Python

That's the new syntax for explicit relative imports. It means import from the current package.

Solution 2 - Python

The dot in the module name is used for relative module import (see here and here, section 6.4.2).

You can use more than one dot, referring not to the curent package but its parent(s). This should only be used within packages, in the main module one should always use absolute module names.

Solution 3 - Python

default one dot in your current folder, when you want to go parent folder you can do like this, my python version 3.6.3

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVlad the ImpalaView Question on Stackoverflow
Solution 1 - PythonKeithView Answer on Stackoverflow
Solution 2 - PythonMartin GuniaView Answer on Stackoverflow
Solution 3 - PythonGinView Answer on Stackoverflow