
举例:想要引入 matplotlib 下面的 animation 模块,import matplotlib.animation会出错,from matplotlib import animation不会。
1 imn1 2018 年 8 月 13 日 看标题还以为你 powershell 写多了 import matplotlib matplotlib.animation ... import matplotlib as a a.animation ... |
2 codechaser OP @imn1 我刚才试了一下,`import matplotlib.animation as animation`也可以。。。 |
3 DiffView 2018 年 8 月 13 日 我还以为是 from .xxx import bbb 呢 |
4 mrchi 2018 年 8 月 13 日 |
5 codechaser OP @mrchi 头像好评 |
6 datou 2018 年 8 月 13 日 python3.6.5 可以使用楼主的引用模块方式 没问题 |
7 gjquoiai 2018 年 8 月 14 日 emm 我猜报错肯定不是 import 报错吧? 如果你写 import matplotlib.animation,调用的时候就得写 matplotlib.animation() 如果你写 from matplotlib import animation,调用的时候就可以写 animation() |
&nbs; 8 codechaser OP @gjquoiai 是这样的,老哥。我看了一下 tutorial 里的关于包的那一章,感觉有点收获 |
9 ps1aniuge 2018 年 8 月 14 日 powershell 就是好。 import matplotlib matplotlib.animation 反人类。 ================== 在 ps 中,第一句没必要。 在 ps 中,第二句也可以省略点前面的部分。 因为 ps 的方法,命令,函数都是不重名的。导入的时候,必须 显式! 允许重名。 当然了,你这么做之后,点前面的内容 就需要了。 ================== 这就好像,领导直接含张三。就是叫自己部门张三。 如果有两个张三,就喊 销售部.张三。一个道理。 ================== 我说的大家能听懂么? ps 这里就是好。 |