Revision: 4748
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4748&view=rev
Author: astraw
Date: 2007-12-16 12:53:35 -0800 (Sun, 16 Dec 2007)
Log Message:
-----------
rec2csv does not close filehandles passed in open
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/cbook.py
trunk/matplotlib/lib/matplotlib/mlab.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2007-12-16 19:28:46 UTC (rev 4747)
+++ trunk/matplotlib/CHANGELOG 2007-12-16 20:53:35 UTC (rev 4748)
@@ -1,3 +1,6 @@
+2007-12-16 rec2csv saves doubles without losing precision. Also, it
+ does not close filehandles passed in open. - JDH,ADS
+
2007-12-13 Moved rec2gtk to matplotlib.toolkits.gtktools and rec2excel
to matplotlib.toolkits.exceltools - JDH
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py 2007-12-16 19:28:46 UTC (rev
4747)
+++ trunk/matplotlib/lib/matplotlib/cbook.py 2007-12-16 20:53:35 UTC (rev
4748)
@@ -224,7 +224,7 @@
except TypeError: return False
else: return True
-def to_filehandle(fname, flag='r'):
+def to_filehandle(fname, flag='r', return_opened=False):
"""
fname can be a filename or a file handle. Support for gzipped
files is automatic, if the filename ends in .gz. flag is a
@@ -236,10 +236,14 @@
fh = gzip.open(fname, flag)
else:
fh = file(fname, flag)
+ opened = True
elif hasattr(fname, 'seek'):
fh = fname
+ opened = False
else:
raise ValueError('fname must be a string or file handle')
+ if return_opened:
+ return fh, opened
return fh
def flatten(seq, scalarp=is_scalar):
Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py 2007-12-16 19:28:46 UTC (rev
4747)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2007-12-16 20:53:35 UTC (rev
4748)
@@ -2335,13 +2335,14 @@
for i, name in enumerate(r.dtype.names):
funcs.append(csvformat_factory(formatd[name]).tostr)
- fh = cbook.to_filehandle(fname, 'w')
+ fh, opened = cbook.to_filehandle(fname, 'w', return_opened=True)
writer = csv.writer(fh, delimiter=delimiter)
header = r.dtype.names
writer.writerow(header)
for row in r:
writer.writerow([func(val) for func, val in zip(funcs, row)])
- fh.close()
+ if opened:
+ fh.close()
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins