[Numpy-svn] r6124 - trunk/numpy/lib

numpy-svn@scip... numpy-svn@scip...
Sat Nov 29 08:54:49 CST 2008


Author: stefan
Date: 2008-11-29 08:54:29 -0600 (Sat, 29 Nov 2008)
New Revision: 6124

Modified:
   trunk/numpy/lib/io.py
Log:
Add bz2 support to loadtxt [patch by Ryan May].

Modified: trunk/numpy/lib/io.py
===================================================================
--- trunk/numpy/lib/io.py	2008-11-29 14:53:44 UTC (rev 6123)
+++ trunk/numpy/lib/io.py	2008-11-29 14:54:29 UTC (rev 6124)
@@ -279,8 +279,8 @@
     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 @@
         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'):



More information about the Numpy-svn mailing list