usb device identification

后端 未结 4 1418
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 07:12

i am using python on ubuntu 9.04 say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like

if usb port

4条回答
  •  爱一瞬间的悲伤
    2020-12-09 07:18

    Ok i was also googling around for answers, here is snippet that works:

    def locate_usb():
    import win32file
    drive_list = []
    drivebits=win32file.GetLogicalDrives()
    for d in range(1,26):
        mask=1 << d
        if drivebits & mask:
            # here if the drive is at least there
            drname='%c:\\' % chr(ord('A')+d)
            t=win32file.GetDriveType(drname)
            if t == win32file.DRIVE_REMOVABLE:
                drive_list.append(drname)
    return drive_list
    

    taken from https://mail.python.org/pipermail/python-win32/2006-December/005406.html

提交回复
热议问题