问答详情
源自:4-1 defaultdict的功能详解

为何不能Import 所有

为什么不能直接import collections


而是需要from collections import XXXXX

提问者:耿直不好么 2018-09-08 01:58

个回答

  • python_me
    2018-09-09 15:49:21

    当然可以啊,直接导入py文件模块,或者Python包目录。

    然后用```.```方法继续一层一层的访问到其中的Python模块或者类方法或者一般方法。

    import collections
    
    User = collections.namedtuple("User", ['name', 'age', 'height'])
    user = User(name="mine", age=99, height=179)
    print('name:', user.name, "\n", 'age:', user.age, "\n", 'height:', user.height)

    最后:你觉得使用起来方便吗?