how to sort a list by the nth element in v2.3?
<p>This is a simple script I wrote: </p>

<pre><code>#!/usr/bin/env python

file = open('readFile.txt', 'r')
lines = file.readlines()
file.close()
del file

sortedList = sorted(lines, key=lambda lines: lines.split('\t')[-2])

file = open('outfile.txt', 'w')
for line in sortedList:
    file.write(line)

file.close()
del file
</code></pre>

<p>to rewrite a file like this:</p>

<pre><code>161788  group_monitor.sgmops    4530    1293840320  1293840152
161789  group_atlas.atlas053    22350   1293840262  1293840152
161790  group_alice.alice017    210     1293840254  1293840159
161791  group_lhcb.pltlhc15     108277  1293949235  1293840159
161792  group_atlas.sgmatlas    35349   1293840251  1293840160
</code></pre>

<p>(where the last two fields are epoch time) ordered by the next to last field to this: </p>

<pre><code>161792  group_atlas.sgmatlas    35349   1293840251  1293840160
161790  group_alice.alice017    210     1293840254  1293840159
161789  group_atlas.atlas053    22350   1293840262  1293840152
161788  group_monitor.sgmops    4530    1293840320  1293840152
161791  group_lhcb.pltlhc15     108277  1293949235  1293840159
</code></pre>

<p>As you can see, I used <code>sorted()</code>, which was introduced in v2.4, how can I rewrite the script for v2.3, so that it does that same thing. 
In addition, I want to convert the epoch time to the human-readable format, so the resultant file looks like this:</p>

<pre><code>161792  group_atlas.sgmatlas    35349   01/01/11 00:04:11   01/01/11 00:02:40
161790  group_alice.alice017    210     01/01/11 00:04:14   01/01/11 00:02:39
161789  group_atlas.atlas053    22350   01/01/11 00:04:22   01/01/11 00:02:32
</code></pre>

<p>I know, this <code>strftime("%d/%m/%y %H:%M:%S", gmtime())</code> can be used to convert the epoch time but I just can't figure out how can I apply that to the script to rewrite the file in that format.</p>

<p>Comments? Advice treasured!
<hr>
<strong>@Mark: Update</strong></p>

<p>In some cases, the epoch time comes as <code>3600</code>, which is to indicate an unfinished business. I wanted to print <em>aborted</em> instead of <code>01/01/1970</code> for such a line. So, I changed the <code>format_seconds_since_epoch()</code> like this:</p>

<pre><code>def format_seconds_since_epoch(t):
    if t == 3600:
        return "aborted"
    else:
        return strftime("%d/%m/%y %H:%M:%S",datetime.fromtimestamp(t).timetuple())
</code></pre>

<p>which solved the problem. Is it the best that can be done in this regard? Cheers!!  </p>
