diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-05-13 12:47:04 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-05-13 12:47:04 +0000 |
commit | 13918161ec7dfe6f7ce1fb871cf978a564d80df3 (patch) | |
tree | deb91a022ca229876d5c267ac04a621103b58a1b /numpy/lib | |
parent | b022b9c5d2e49d1d2ab07be0fe4549342ab88c1e (diff) | |
download | numpy-13918161ec7dfe6f7ce1fb871cf978a564d80df3.tar.gz |
BUG/3K: lib: make savetxt work with filenames
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/npyio.py | 7 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 11 |
2 files changed, 14 insertions, 4 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index a1c55b23f..4310aacd0 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -27,7 +27,6 @@ if sys.version_info[0] >= 3: else: from cStringIO import StringIO as BytesIO -_file = open _string_like = _is_string_like def seek_gzip_factory(f): @@ -285,7 +284,7 @@ def load(file, mmap_mode=None): 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 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n'): 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: diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index a50c6f267..73d3c3599 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -225,6 +225,17 @@ class TestSaveTxt(TestCase): 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): |