简体   繁体   中英

What does `import ...` mean in Python 3?

From a quick search, I know that one dot means in the current directory, two dots mean in the parent directory, and three dots mean in the grandparent directory, but these examples are usually written as from .. import PackageName

What if the code was just import ... ? Does this import every file in the grandparent directory? (The reason why I ask is that I'm working with some files that has this import statement at the top, but there is nothing in the grandparent directory to import).

The dots mimic the Unix file system that . refers to the current directory and .. refers to the parent. ... has no such conventional meaning. In Python, however, ... is the literal for the singleton value of the ellipsis class:

>>> type(...)
<class 'ellipsis'>

As such, import ... would be a syntax error, as ... is not a valid module name.

What if the code was just import ...?

as @chepner said, ... means <class 'ellipsis'>, but you can't import it.

in PyCharm "import ..." means it is a folded code block:

在此处输入图片说明

the full code is like this(click the “+” button):

在此处输入图片说明

Maybe other IDEs are like this too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM