Completely new to python i’m having problems finding this with version 2.4
I have a text file that contains 3 columns they are tab delimited by not a single tab, 9 tabs.
1000 line file
ex:
$1$sda4356:[sgb1_diska5.ldlbat44.libabl]talild_0329_base.rpt talild_0329_base.rpt 00000000000000005062
What i need to do is sort everything by column 3 ( 00000000000000005062 ).
Is using the csv reader the best way to handle doing this? how do i get it to handle the fact that my text file is using 9 tabs to seperate each column. Most other things i’m finding are incompatiable with python 2.4.
Since you’re using 9 tabs,
str.splitseems like it should be able to handle this properly, (but I don’t see any reason whycsvwould choke on it …):Or possibly:
Then you can sort that. In a newer version of python, you’d do:
Try this first! (According to the comments and the documentation,
keyis supported in python2.4, but not python2.3).operator.itemgetteris also “new in python2.4” anditemgetter(2)is equivalent tolambda x:x[2]or the more verbose:But I think you might need to rely on
cmpfor compatability with really old python versions (Note, that python3 no longer supportscmp):and then you’d sort: