On Thursday 29 October 2009 05:10:38 pm JJWMac wrote:
> Back in February, Marshall Hampton posted in response to a query about
> reading a csv file.
>
> ****************
> I am tempted to open a ticket in trac for some sort of read_csv
> command, which might behave like the following (NOTE: this is just
> wishful thinking at this point):
>
> data_list = read_csv('my_file.csv') # data_list would be a list of
> lists of row data, converted to numerical types if possible
> data_list = read_csv('my_file.csv', seperator = '\t')  #split lines by
> a tab character instead
> data_list = read_csv('my_file.csv', fields = [int,int,string])
> #perhaps useful to have more explicit field conversions
> ****************
>
> Basically, I am asking, does such a simple dataarray = read_csv(..)
> type command/function (with formatting codes) now exist somewhere?

sage: !cat thing.csv
First,Last,Address
"Sam","Smith","Hillbilly Ave"
"Jack","McDonald","Spring St"
sage: import csv
sage: m=csv.reader(open("thing.csv","r"))
sage: for l in m: print l
....:
['First', 'Last', 'Address']
['Sam', 'Smith', 'Hillbilly Ave']
['Jack', 'McDonald', 'Spring St']


http://docs.python.org/library/csv.html

--
Joel

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to