这取决于操作系统 在 Linux 中,您可以为此使用 pyudev : 几乎公开了完整的 libudev 功能。你可以: 枚举设备,按特定条件过滤(pyudev.Context) 查询设备信息、属性和属性, 监视设备,与后台线程同步和异步,或在 Qt(pyudev.pyqt4、pyudev.pyside)、glib(pyudev.glib)和 wxPython(pyudev.wx)的事件循环中。 https://pyudev.readthedocs.io/en/latest/ 源代码在 http://pyudev.readthedocs.io/en/v0.14/api/monitor.html ,见 receive_device() 功能 在 Windows 中,您可以使用 WMI(Windows Management Instrumentation),如 https://blogs.msdn.microsoft.com/powershell/2007/02/24/displaying-usb-devices-using-wmi/(Python 阅读设备管理器信息)或 python 绑定,如 https://pypi.python.org/pypi/infi.devicemanager 原文由 ralf htp 发布,翻译遵循 CC BY-SA 3.0 许可协议
这取决于操作系统
在 Linux 中,您可以为此使用
pyudev
:https://pyudev.readthedocs.io/en/latest/
源代码在 http://pyudev.readthedocs.io/en/v0.14/api/monitor.html ,见
receive_device()
功能在 Windows 中,您可以使用 WMI(Windows Management Instrumentation),如 https://blogs.msdn.microsoft.com/powershell/2007/02/24/displaying-usb-devices-using-wmi/(Python 阅读设备管理器信息)或 python 绑定,如 https://pypi.python.org/pypi/infi.devicemanager