当您在 python 脚本中看到 "from a.b import c" 时,a、b、c 的类型?

Types of a,b,c when you see "from a.b import c" in a python script?

当我看到

from a.b import c

在 python 脚本中,我可以安全地假设

?我做出这些假设是因为 the official document on python modules 是这样说的:

There is a variant of the import statement that imports names from a module directly into the importing module’s symbol table. For example:

from fibo import fib, fib2 fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

所以,按照这个文档,“from”之后的东西,也就是上面的fibo,应该是一个模块吧? (上面的第一个假设)

from a.b import c

为了简单起见,这里a是包(它基本上是一个文件夹,虽然它有一些特殊的属性),b.py是包下的文件名ac 是 class 或在 b.py 中被污染的函数。 另外,这里的a可能是一个包,b是一个sub-package,c.py可能是文件名。如果是这样,那么如果c.py中有一个函数my_function,你需要在你的程序中使用c.my_function。

有关详细信息,请查看 https://docs.python.org/3/reference/import.html