问题
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