Addressing python objects

此生再无相见时 提交于 2020-01-03 16:56:28

问题


I'm trying to use ncclient for Python.

If I do this it works:

from ncclient import manager
m = manager.connect()

If I do this it fails:

import ncclient
m = ncclient.manager.connect()

The error is AttributeError: 'module' object has no attribute 'manager'.

I don't understand what the difference is. Shouldn't that be the same method either way? Why isn't it?


回答1:


Importing a module (package) does not automatically import submodule. (Some modules do. For example, importing os module also import os.path)

Replace following line:

import ncclient

with:

import ncclient.manager

to load the submodule manager.



来源:https://stackoverflow.com/questions/23965201/addressing-python-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!