On Sun, Jan 25, 2009 at 3:59 PM, C Lewis <[email protected]> wrote:
> Tiny case appended.
>
> On my system (OS X), csv2rec() of the first file is fine, csv2rec() of the
> second fails with the mentioned error; they only differ in newline
> characters. Inconveniently, the one that fails seems to be Excel's default
> export.
OK, I can reproduce the problem and the solution is easy. Open the
file in universal mode and pass the file handle to csv2rec::
fh= file('myfile.csv', 'rU')
r = csv2rec(fh)
fh.close()
Here is an example ipython session:
In [2]: import matplotlib.mlab
In [3]: r = matplotlib.mlab.csv2rec('tr
triangleplot_demo2.csv try
In [3]: r = matplotlib.mlab.csv2rec('triangleplot_demo2.csv')
---------------------------------------------------------------------------
Error Traceback (most recent call last)
/Users/jdhunter/Desktop/<ipython console> in <module>()
/Users/jdhunter/dev/lib/python2.5/site-packages/matplotlib/mlab.pyc in
csv2rec(fname, comments, skiprows, checkrows, delimiter, converterd,
names, missing, missingd, use_mrecords)
2513
2514 if needheader:
-> 2515 for row in reader:
2516 #print 'csv2rec', row
2517 if len(row) and row[0].startswith(comments):
Error: new-line character seen in unquoted field - do you need to open
the file in universal-newline mode?
In [4]: fh = file('triangleplot_demo2.csv', 'rU')
In [5]: r = matplotlib.mlab.csv2rec(fh)
In [6]: fh.close()
In [7]: print r.dtype
[('sand', '<i4'), ('silt', '<i4'), ('clay', '<i4'), ('om', '<i4'),
('porosity', '<i4'), ('site', '|S3')]
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users