[Tutor] compare and arrange file

Edgar Almonte samudhio at gmail.com
Wed Jul 13 01:01:32 CEST 2011


On Tue, Jul 12, 2011 at 5:44 AM, Peter Otten <__peter__ at web.de> wrote:
> Edgar Almonte wrote:
>
>> thanks emile i understand exactly what you explain me but i was unable
>> to accomplish it ( too noob in python ) but i solved the problem with
>> this code
>> http://pastebin.com/4A6Jz4wZ
>>
>> i will try do what you suggest me anyway but that will tomorrow ,
>> tonight i done and i feel good :D
>
> When you're done compare it to the one below:
>

>
> import csv
>
> def sortkey(row):
>    if float(row[1]):
>        return row[1], True
>    else:
>        return row[2], False
>
> with open("infile.txt", "rb") as instream:
>    rows = sorted(csv.reader(instream, delimiter="|"), key=sortkey)
>
> with open("outfile.txt", "wb") as outstream:
>    csv.writer(outstream, delimiter="|").writerows(rows)
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

That code work flawless , aweasome , can you explain to me the code, i
have a idea but if you don't mind can you ?


More information about the Tutor mailing list