diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/npyio.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index feb336dcc..7a6e0238a 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -584,7 +584,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, import bz2 fh = bz2.BZ2File(fname) else: - fh = file(fname) + fh = file(fname, 'U') elif hasattr(fname, 'readline'): fh = fname else: diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index a61382792..a50c6f267 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -403,6 +403,16 @@ class TestLoadTxt(TestCase): dtype=ndtype) assert_equal(test, control) + def test_universal_newline(self): + f, name = mkstemp() + os.write(f, asbytes('1 21\r3 42\r')) + os.close(f) + + try: + data = np.loadtxt(name) + assert_array_equal(data, [[1, 21], [3, 42]]) + finally: + os.unlink(name) class Testfromregex(TestCase): |