对 Python 的模块不能进行`.`导入吗? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
codechaser

对 Python 的模块不能进行`.`导入吗?

  •  
  •   codechaser 2018 年 8 月 13 日 2687 次点击
    这是一个创建于 2811 天前的主题,其中的信息可能已经有所发展或是发生改变。

    举例:想要引入 matplotlib 下面的 animation 模块,import matplotlib.animation会出错,from matplotlib import animation不会。

    9 条回复    2018-08-14 22:40:39 +08:00
    imn1
        1
    imn1  
       2018 年 8 月 13 日
    看标题还以为你 powershell 写多了

    import matplotlib
    matplotlib.animation ...

    import matplotlib as a
    a.animation ...
    codechaser
        2
    codechaser  
    OP
       2018 年 8 月 13 日
    @imn1 我刚才试了一下,`import matplotlib.animation as animation`也可以。。。
    DiffView
        3
    DiffView  
       2018 年 8 月 13 日
    我还以为是 from .xxx import bbb 呢
    mrchi
        4
    mrchi  
       2018 年 8 月 13 日
    ![屏幕快照.png]( https://i.loli.net/2018/08/13/5b71012aad08e.png)

    没有报错 Ubuntu 16.04
    codechaser
        5
    codechaser  
    OP
       2018 年 8 月 13 日
    @mrchi 头像好评
    datou
        6
    datou  
       2018 年 8 月 13 日
    python3.6.5 可以使用楼主的引用模块方式

    没问题
    gjquoiai
        7
    gjquoiai  
       2018 年 8 月 14 日
    emm 我猜报错肯定不是 import 报错吧?
    如果你写 import matplotlib.animation,调用的时候就得写 matplotlib.animation()
    如果你写 from matplotlib import animation,调用的时候就可以写 animation()
    codechaser
      &nbs; 8
    codechaser  
    OP
       2018 年 8 月 14 日 via Android
    @gjquoiai 是这样的,老哥。我看了一下 tutorial 里的关于包的那一章,感觉有点收获
    ps1aniuge
        9
    ps1aniuge  
       2018 年 8 月 14 日
    powershell 就是好。
    import matplotlib
    matplotlib.animation
    反人类。
    ==================
    在 ps 中,第一句没必要。
    在 ps 中,第二句也可以省略点前面的部分。
    因为 ps 的方法,命令,函数都是不重名的。导入的时候,必须 显式! 允许重名。
    当然了,你这么做之后,点前面的内容 就需要了。
    ==================
    这就好像,领导直接含张三。就是叫自己部门张三。
    如果有两个张三,就喊 销售部.张三。一个道理。
    ==================
    我说的大家能听懂么? ps 这里就是好。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2857 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 62ms UTC 13:35 PVG 21:35 LAX 06:35 JFK 09:35
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86