Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

list devices python 3

import re
import subprocess
device_re = re.compile(b"Buss+(?P<bus>d+)s+Devices+(?P<device>d+).+IDs(?P<id>w+:w+)s(?P<tag>.+)$", re.I)
df = subprocess.check_output("lsusb")
devices = []
for i in df.split(b'
'):
    if i:
        info = device_re.match(i)
        if info:
            dinfo = info.groupdict()
            dinfo['device'] = '/dev/bus/usb/%s/%s' % (dinfo.pop('bus'), dinfo.pop('device'))
            devices.append(dinfo)
            
print(devices)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #list #devices #python
ADD COMMENT
Topic
Name
5+5 =