Marshall Hampton wrote:
> Sometimes its convenient to use the DATA directory, which will be
> packaged with the worksheet if you save it (as a .sws file).  So for
> example you could copy the file to the DATA directory doing something
> like:
> 
> os.system('cp /full/path/to/list2.txt ' + DATA + 'list2.txt')
> 
> and then
> 
> f = open(DATA + 'list2.txt')
> 
> should work, and would still work if you saved a worksheet copy and
> moved it to another computer.
> 
> 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
> 
> Does something like that already exist?  Seems very common as a task.
> Of course its not that hard to do ad-hoc, but it would make things
> more user-friendly for lots of people I think.

Yes, python has a very nice CSV module.  See 
http://www.python.org/doc/2.5.2/lib/module-csv.html

Thanks,

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to