[Tutor] Variable data to CSV
Thomas Toker
thomas.toker at yahoo.com
Fri Feb 27 21:00:29 CET 2015
Hey all so I'm new to python(like 2 days ago new) I need to find the device address, usb port, and number of times the error occurs Heres what I have:
import re import csv
import reimport csvf = open("file.txt", "r") #location of log file
searchlines = f.readlines() #create list from filef.close()for element in searchlines: usbPres = re.search('(USB)',element) #pattern to find usb lines devAddr = re.search('(address)\s\d+',element) #parsing pattern for device address port = re.search('(port)\s\d',element) #parsing pattern for port if usbPres: This is where I get lost because I want to assign the correct port to device address and then count number of time it failed before a new device is inserted into that port. then write it to a CSV
**** SAMPLE TEXT ***
[11883.112089] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11883.224080] usb 1-7: new high speed USB device using ehci_hcd and address 42
[11883.328151] hub 1-0:1.0: unable to enumerate USB device on port 7
[11904.472097] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11907.440096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11910.408093] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11913.376095] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11913.616090] usb 1-7: new high speed USB device using ehci_hcd and address 47
[11913.716121] hub 1-0:1.0: unable to enumerate USB device on port 7
[11927.340096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11930.308096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11933.276124] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11936.244118] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11939.212116] hub 1-0:1.0: Cannot enable port 7. Maybe the USB cable is bad?Any help is much appreciated.Tom
More information about the Tutor
mailing list