I'm having some trouble sorting data from a text file by a certain field. Possibly by multiple fields later. The .txt is several thousands of lines of code. I'm brand new to python so my code is probably a bit messy. For example, this is the textfile i would read from:
stuff
123 1200 id-aaaa [email protected]
322 1812 id-wwww [email protected]
839 1750 id-wwww [email protected]
500 0545 id-aaaa [email protected]
525 1322 id-bbbb [email protected]
my code so far is as follows:
filelist = open("info.txt").readlines()
splitlist = list()
class data:
def __init__(self, eventName, time, identity, domain):
self.evenName = eventName
self.time = time
self.identity = identity
self.domain = domain
for line in filelist:
filelist = list.split(', ')
splitlist.append(filelist)
for column in splitlist:
if (len(column) > 1): #to skip the first line
eventName = column[0].strip()
time = column[1].strip()
identity = column[2].strip()
domain = column[3].strip()
I want to sort the .txt file line by line by the identity, then maybe by time. I saw that this could be done by classes in the python tutorial, so i'm trying to go that route. Please advise. Thank you!
stuffin the text file, or the name of the text file?