Python object addressing

I am trying to use ncclient for Python.

If I do this, it works:

from ncclient import manager
m = manager.connect()

If I do this, this will not work:

import ncclient
m = ncclient.manager.connect()

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

I donโ€™t understand what the difference is. Shouldn't it be the same way? Why is this not so?

+4
source share
1 answer

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

Replace the following line:

import ncclient

with:

import ncclient.manager

to load a submodule manager.

+6
source

Source: https://habr.com/ru/post/1542727/


All Articles