Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'context': 0.04; 'sys': 0.05; 'prints': 0.07; 'python': 0.08; '>>>>': 0.09; '__name__': 0.09; 'from:addr:python': 0.09; 'nameerror:': 0.09; 'url:packages': 0.09; 'def': 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'subject:drive': 0.16; 'wrote:': 0.16; 'insert': 0.19; 'defined': 0.19; 'skip:m 30': 0.19; 'seems': 0.20; 'wrote': 0.20; '(most': 0.21; 'trying': 0.21; 'subject:data': 0.21; 'header:In-Reply-To:1': 0.22; 'sep': 0.23; 'pm,': 0.24; 'traceback': 0.24; 'code': 0.25; 'fine': 0.26; 'skip:p 30': 0.28; 'monitor': 0.28; 'received:84': 0.28; 'problem': 0.28; 'import': 0.28; 'print': 0.29; 'script': 0.29; 'error': 0.32; 'does': 0.32; 'to:addr:python-list': 0.33; '...': 0.34; 'header:User-Agent:1': 0.34; 'skip:= 10': 0.34; 'last):': 0.34; 'reply- to:addr:python.org': 0.34; 'thank': 0.35; 'problem.': 0.36; 'file': 0.36; 'url:python': 0.36; 'device': 0.36; 'using': 0.37; 'but': 0.37; 'could': 0.38; 'think': 0.38; 'some': 0.38; 'url:org': 0.38; 'subject:: ': 0.39; 'manually': 0.39; 'getting': 0.39; 'empty': 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; 'skip:d 20': 0.39; 'url:index': 0.61; 'devices': 0.63; 'link': 0.63; 'kindly': 0.65; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'usb': 0.73; 'mount': 0.84; 'observer': 0.84; 'skip:d 60': 0.84; 'drive.': 0.91; 'url:api': 0.91; 'skip:d 50': 0.93 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EAIZfYk5UXebj/2dsb2JhbABCqGx4gUYBAQU4QBELCBAJFg8JAwIBAgENAjYTCAEBF4daArZdhmoEi3JJiUCCQot/ Date: Sat, 03 Sep 2011 18:16:01 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Reading pen drive data References: <3c05935f-3e0b-4b1b-afca-889c63e5b650@r8g2000prd.googlegroups.com> <4ee9b05c-b1cf-4542-a3af-6a42b669c37f@a10g2000prn.googlegroups.com> In-Reply-To: <4ee9b05c-b1cf-4542-a3af-6a42b669c37f@a10g2000prn.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315070162 news.xs4all.nl 2448 [2001:888:2000:d::a6]:54689 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12710 On 03/09/2011 17:21, mukesh tiwari wrote: > On Sep 3, 7:40 pm, mukesh tiwari wrote: >> Hello all >> I am trying to write a python script which can mount a pen drive and >> read the data from pen drive. I am using pyudev [http://packages.python.org/pyudev/api/index.html] and wrote a small >> python code >> >> import pyudev, sys >> if __name__ =="__main__": >> context = pyudev.Context() >> devices = context.list_devices(subsystem ="usb") >> for device in devices : >> print device >> >> which prints >> >> Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3') >> Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3/3-0:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4') >> Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4/4-0:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5') >> Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5/5-0:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1') >> Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1/1-0:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-0:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2/6-2:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7/7-0:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8/8-0:1.0') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2') >> Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-0:1.0') >> >> My problem is, how to know out of these usb which one to read . The >> other solution I got is whenever I insert the pen drive , my system >> mounts it in /media directory so I can read the /media directory to >> check if its empty or not but this does not seems promising to me >> because it may be possible that my system is not able to mount the pen >> drive so I have to manually do it . Kindly some one please tell me >> how to solve this problem. > > I got this link and its working fine [ http://packages.python.org/pyudev/api/monitor.html > ] >>>> context = pyudev.Context() >>>> monitor = pyudev.Monitor.from_netlink(context) >>>> monitor.filter_by(subsystem='input') >>>> for action, device in monitor: > ... print('{0}: {1}'.format(action, device)) > > but when I am trying to execute code [ http://packages.python.org/pyudev/api/toolkit.html > ] > > import pyudev, sys > > context = pyudev.Context() > monitor = pyudev.Monitor.from_netlink(context) > monitor.filter_by(subsystem='usb') > observer = QUDevMonitorObserver(monitor) > def device_connected(device): > print('{0!r} added'.format(device)) > observer.deviceAdded.connect(device_connected) > monitor.start() > > I am getting > Traceback (most recent call last): > File "Mount.py", line 7, in > observer = QUDevMonitorObserver(monitor) > NameError: name 'QUDevMonitorObserver' is not defined > > Could any one please tell me how to avoid this error . > Thank you I think you need to import it from pyudev.pyqt4.