テキスト ファイルのデータを特定のフィールドで並べ替えるのに問題があります。おそらく後で複数のフィールドによって。.txt は数千行のコードです。私は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 ファイルを 1 行ずつ ID で並べ替え、次に時間で並べ替えたいと考えています。これは Python チュートリアルのクラスで実行できることがわかったので、その方法を試しています。お知らせ下さい。ありがとうございました!