From 00f70117aed4a20bfa8770560e1759f769ada527 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 29 Nov 2008 14:54:29 +0000 Subject: Add bz2 support to loadtxt [patch by Ryan May]. --- numpy/lib/io.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'numpy/lib/io.py') 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'): -- cgit v1.2.1