On Sun, Oct 11, 2009 at 6:10 PM, Utkarsh "" <[email protected]> wrote:
> Hello, I have a CSV file, from which I want to extract data.
> The CSV file is arranged like this:
>
> Time, InSec, Open, High, Low, Close, Qty
> 09:55:17,35717,41.95,41.95,41.95,41.95,105
> 09:56:03,35763,41.75,41.75,41.75,41.75,20785
> 09:56:40,35800,41.75,41.75,41.75,41.75,8950
>
> I wanted to extract each column, and put the data in a list, with a list
> for each column.
> I'm using the following code to perform this action:
>
> Time, InSec, Open, High, Low, Close, Volume = [], [], [], [], [], [],
> []
> thefile = open('somefile.CSV', 'r')
> linelist = thefile.readline()
> while linelist != '':
> b = linelist.split(',')
> Time.append(b[0])
> InSec.append(b[1])
> Open.append(b[2])
> High.append(b[3])
> Low.append(b[4])
> Close.append(b[5])
> Volume.append(b[6])
> linelist = thefile.readline()
>
> Is there any other, better and more pythonic way to do this ?
>
> you can take a look at csv module
http://docs.python.org/library/csv.html
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Vishwajeet Singh
+91-9657702154 | [email protected] | http://singhvishwajeet.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
http://www.linkedin.com/in/singhvishwajeet
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor