[Numpy-svn] r8411 - in trunk/numpy/lib: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Thu May 13 08:47:07 EDT 2010
Author: ptvirtan
Date: 2010-05-13 07:47:04 -0500 (Thu, 13 May 2010)
New Revision: 8411
Modified:
trunk/numpy/lib/npyio.py
trunk/numpy/lib/tests/test_io.py
Log:
BUG/3K: lib: make savetxt work with filenames
Modified: trunk/numpy/lib/npyio.py
===================================================================
--- trunk/numpy/lib/npyio.py 2010-05-13 10:55:09 UTC (rev 8410)
+++ trunk/numpy/lib/npyio.py 2010-05-13 12:47:04 UTC (rev 8411)
@@ -27,7 +27,6 @@
else:
from cStringIO import StringIO as BytesIO
-_file = open
_string_like = _is_string_like
def seek_gzip_factory(f):
@@ -285,7 +284,7 @@
import gzip
if isinstance(file, basestring):
- fid = _file(file, "rb")
+ fid = open(file, "rb")
elif isinstance(file, gzip.GzipFile):
fid = seek_gzip_factory(file)
else:
@@ -792,9 +791,9 @@
fh = gzip.open(fname, 'wb')
else:
if sys.version_info[0] >= 3:
- fh = file(fname, 'wb')
+ fh = open(fname, 'wb')
else:
- fh = file(fname, 'w')
+ fh = open(fname, 'w')
elif hasattr(fname, 'seek'):
fh = fname
else:
Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py 2010-05-13 10:55:09 UTC (rev 8410)
+++ trunk/numpy/lib/tests/test_io.py 2010-05-13 12:47:04 UTC (rev 8411)
@@ -225,7 +225,18 @@
lines = c.readlines()
assert_equal(lines, asbytes_nested(['01 : 2.0\n', '03 : 4.0\n']))
+ def test_file_roundtrip(self):
+ f, name = mkstemp()
+ os.close(f)
+ try:
+ a = np.array([(1, 2), (3, 4)])
+ np.savetxt(name, a)
+ b = np.loadtxt(name)
+ assert_array_equal(a, b)
+ finally:
+ os.unlink(name)
+
class TestLoadTxt(TestCase):
def test_record(self):
c = StringIO()
More information about the Numpy-svn
mailing list