Why does the way pynput.mouse.Controller is imported matter?
Answer a question I am using pynput.mouse.Controller to listen for certain mouse actions and also using it to navigate to certain targets. When I import Controller as follows: from pynput.mouse import
Answer a question
I am using pynput.mouse.Controller to listen for certain mouse actions and also using it to navigate to certain targets.
When I import Controller as follows: from pynput.mouse import Controller
everything works fine and the programs runs smoothly.
However, when I do this instead import pynput.mouse.Controller
I receive an error telling ModuleNotFoundError: No module named 'pynput.mouse.Controller'
Unless I am having a fundemental misunderstanding, these lines should function the same. Is there any reason why one produces an error but the other doesn't?
Answers
import
imports modules or packages (directories with __init__.py
), it cannot import objects from modules. This doesn't work:
import pynput.mouse.Controller
This work:
import pynput.mouse
Controller = pynput.mouse.Controller
This also work:
from pynput input mouse
Controller = mouse.Controller
And this:
from pynput.mouse import Controller
更多推荐
所有评论(0)