diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2008-11-29 14:54:29 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2008-11-29 14:54:29 +0000 |
commit | 00f70117aed4a20bfa8770560e1759f769ada527 (patch) | |
tree | 5b1bf7ed96bebe97dec0b5f1cc13e2f2a0c1b742 | |
parent | b1343ae09fbfde2ba7e5ceaf734d73168de45fd2 (diff) | |
download | numpy-00f70117aed4a20bfa8770560e1759f769ada527.tar.gz |
Add bz2 support to loadtxt [patch by Ryan May].
-rw-r--r-- | numpy/lib/io.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/numpy/lib/io.py b/numpy/lib/io.py index b85022203..e9a012db1 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -279,8 +279,8 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, Parameters ---------- fname : file or string - File or filename to read. If the filename extension is ``.gz``, - the file is first decompressed. + File or filename to read. If the filename extension is ``.gz`` or + ``.bz2``, the file is first decompressed. dtype : data-type Data type of the resulting array. If this is a record data-type, the resulting array will be 1-dimensional, and each row will be @@ -346,6 +346,9 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, if fname.endswith('.gz'): import gzip fh = gzip.open(fname) + elif fname.endswith('.bz2'): + import bz2 + fh = bz2.BZ2File(fname) else: fh = file(fname) elif hasattr(fname, 'readline'): |