python123读取文本文件并排序输出_Python按字段对文本文件排序
按某個字段對文本文件中的數(shù)據(jù)進行排序時遇到問題。以后可能會有多個字段。txt是數(shù)千行代碼。我是python新手,所以我的代碼可能有點混亂。例如,這是我將從中讀取的文本文件:stuff
123 1200 id-aaaa stuart@test.com
322 1812 id-wwww machine-switch@test.com
839 1750 id-wwww gary2-da@test.com
500 0545 id-aaaa abc123@test.com
525 1322 id-bbbb zyx321@test.com
我的代碼如下: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()
我想按標識對.txt文件逐行排序,然后可能按時間排序。我在python教程中看到,這可以通過類來完成,所以我正試圖走這條路。請告知。謝謝您!
總結(jié)
以上是生活随笔為你收集整理的python123读取文本文件并排序输出_Python按字段对文本文件排序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 噪声与振动控制工程手册_声学分享客噪声与
- 下一篇: python文本替换 数据库_在Pyth