Obtain device path from pyudev with python
<p>Using pydev with <code>python-2.7</code>, I wish obtain the device path of connected devices. </p>

<p>Now I use this code:</p>

<pre><code>from pyudev.glib import GUDevMonitorObserver as MonitorObserver

def device_event(observer, action, device):
    print 'event {0} on device {1}'.format(action, device)
</code></pre>

<p>but <code>device</code> return a string like this:</p>

<blockquote>
  <p>(u'/sys/devices/pci0000:00/pci0000:00:01.0/0000.000/usb1/1-2')</p>
</blockquote>

<p>How can I obtain a path like <code>/dev/ttyUSB1</code> ?</p>

<p>I find this solution:</p>

<pre><code>def device_event (observer, action, device):
    if action == "add":
        last_dev = os.popen('ls -ltr /dev/ttyUSB* | tail -n 1').read()
        print "Last device: " + last_dev
</code></pre>

<p>I know... is horrible. </p>

python usb glib pyudev