当您在 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 脚本中,我可以安全地假设
- a.py 是模块搜索路径上的 python 脚本
- b 是 a
中的 class
- c是b中的一个方法
?我做出这些假设是因为 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
是包下的文件名a
和c
是 class 或在 b.py
中被污染的函数。
另外,这里的a
可能是一个包,b
是一个sub-package,c.py可能是文件名。如果是这样,那么如果c.py中有一个函数my_function,你需要在你的程序中使用c.my_function。
当我看到
from a.b import c
在 python 脚本中,我可以安全地假设
- a.py 是模块搜索路径上的 python 脚本
- b 是 a 中的 class
- c是b中的一个方法
?我做出这些假设是因为 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
是包下的文件名a
和c
是 class 或在 b.py
中被污染的函数。
另外,这里的a
可能是一个包,b
是一个sub-package,c.py可能是文件名。如果是这样,那么如果c.py中有一个函数my_function,你需要在你的程序中使用c.my_function。