[IronPython] Sorting CSV file

Sheetal Gophane sheetal_gophane at persistent.co.in
Fri Jan 23 22:13:46 PST 2009


Thank you all for your suggestions.
I followed the following way
1.Define a class
2.In class overwrite __cmp__ function.
3.While reading file populate class object and append it in array.
4.Call array.sort() method. Internally it calls __cmp__ function.



Thanks,
Sheetal
-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Slide
Sent: Friday, January 23, 2009 9:15 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Sorting CSV file

On Fri, Jan 23, 2009 at 7:28 AM, Michael Foord
<fuzzyman at voidspace.org.uk> wrote:
> Slide wrote:
>>
>> On Fri, Jan 23, 2009 at 6:21 AM, Dody Gunawinata
>> <empirebuilder at gmail.com> wrote:
>>
>>>
>>> 1. Define a class to hold individual data
>>> 2. Go through every single line
>>> 3. Split based on ',' and insert the values to the object and add them
to
>>> the list
>>> 4. Sort the list based on the fields you want.
>>> On Fri, Jan 23, 2009 at 10:28 AM, Sheetal Gophane
>>> <sheetal_gophane at persistent.co.in> wrote:
>>>
>>>>
>>>> Hi All,
>>>>
>>>>
>>>>
>>>> I have csv file in following format
>>>>
>>>> LogTime,ApetClientID,OperationName,Status,StartTime,Duration
>>>>
>>>> 2009-01-07/10:41:03,1,fun1,1,2009-01-07/10:41:02,314.8173162
>>>>
>>>> 2009-01-07/10:41:03,1,Login,0,2009-01-07/10:41:02,618.2695007
>>>>
>>>> 2009-01-07/10:41:03,1,Login,1,2009-01-07/10:40:52,10997.29274
>>>>
>>>> 2009-01-07/10:41:04,1,fun2,1,2009-01-07/10:41:03,364.0241288
>>>>
>>>> 2009-01-07/10:41:04,1,DoLogin,1,2009-01-07/10:40:52,11248.42243
>>>>
>>>> 2009-01-07/10:41:04,1,fun3,1,2009-01-07/10:41:03,1197.179181
>>>>
>>>>
>>>>
>>>> I want to sort this file on the basis of first field i.e. LogTime
>>>>
>>>> Any pointers,how to do this?
>>>>
>>>> Thanks in advance.
>>>>
>>>>
>>>>
>>>> Thanks & Regards,
>>>>
>>>> Sheetal
>>>>
>>>>
>>>>
>>>>
>>
>>
>> Why not use the csv module from the standard library? Should be simple
>> to read the lines in using the CSVReader and have it already split for
>> you. I'd recommend reading it into a dict and then sorting the dict
>> based on that field as was already mentioned.
>>
>
> Isn't the standard library csv module dependent on a C extension?
>
> There are recipes here for reading a CSV with a .NET library and
IronPython:
> http://www.ironpython.info/index.php/Reading_CSV_Files
> http://www.ironpython.info/index.php/Talk:Reading_CSV_Files
>
> Michael
>
>


Ah, could be, although I thought I had used it in IronPython before,
but I could be thinking of something else.

slide


-- 
slide-o-blog
http://slide-o-blog.blogspot.com/
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.


More information about the Users mailing list