How to sort records in file

Grant Edwards grante at
Fri Aug 13 21:29:18 CEST 2004

On 2004-08-13, Lad <export at> wrote:

> What is the best( easiest)way how to sort a file?

$ man sort  


> I have a file where each record consists of 3 fields( 3 words)
> and I would like to sort records by the first field( word)in
> each record.

lines = file('myfilename').readlines()
for l in lines:
    print l,

Grant Edwards                   grante             Yow!  I just had my entire
                                  at               INTESTINAL TRACT coated
                                 with TEFLON!

More information about the Python-list mailing list