The difficulty with accepting an iterator (of strings) is that it is unclear if each item corresponds to a row or an element. But I would be in favor of rather liberal string parsing, so one could do
matrix(open("test.csv").read()) just like matrix(""" 1,2,3 4,5,5 """) On Mon, Feb 27, 2012 at 6:26 AM, Jason Grout <jason-s...@creativetrax.com> wrote: > On 2/24/12 1:32 PM, Volker Braun wrote: >> >> We do get questions about "how to read matrix from csv" quite regularly. >> Of course its just a few lines of code, but I think it would be nice to >> have a matrix_from_file('fname.csv') function that imports csv and >> perhaps others (gnumeric/ooffice/excel). Any volunteers? ;-) >> > > How about the matrix constructor reads from an iterator and recognizes csv? > We could even use the numpy savetxt and loadtxt functions to more > sophisticated parsing. > > So: > > with open('mymatrix.csv','r') as f: > m=matrix(f) > > or > > m.save('test.csv') # or m.save('test.csv', format='csv') > > I'm not volunteering in these suggestions... > > Thanks, > > Jason > > > > -- > 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 -- 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