What does a . in an import statement in Python mea

2019-01-01 15:42发布

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 module
2条回答
时光乱了年华
2楼-- · 2019-01-01 15:45

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.

查看更多
人气声优
3楼-- · 2019-01-01 16:02

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

查看更多
登录 后发表回答