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

numpy-svn@scip... numpy-svn@scip...
Tue Jul 22 10:12:36 CDT 2008


Author: stefan
Date: 2008-07-22 10:12:12 -0500 (Tue, 22 Jul 2008)
New Revision: 5498

Modified:
   trunk/numpy/lib/io.py
Log:
Clean up loadtxt. Fix Python 2.3 compatibility.


Modified: trunk/numpy/lib/io.py
===================================================================
--- trunk/numpy/lib/io.py	2008-07-22 06:37:48 UTC (rev 5497)
+++ trunk/numpy/lib/io.py	2008-07-22 15:12:12 UTC (rev 5498)
@@ -274,6 +274,7 @@
 
     SeeAlso: scipy.io.loadmat to read and write matfiles.
     """
+    user_converters = converters
 
     if _string_like(fname):
         if fname.endswith('.gz'):
@@ -317,26 +318,26 @@
 
     # Read until we find a line with some values, and use
     # it to estimate the number of columns, N.
-    read_line = None
-    while not read_line:
+    first_vals = None
+    while not first_vals:
         first_line = fh.readline()
-        read_line = split_line(first_line)
-    N = len(usecols or read_line)
+        first_vals = split_line(first_line)
+    N = len(usecols or first_vals)
 
     dtype_types = flatten_dtype(dtype)
     if len(dtype_types) > 1:
         # We're dealing with a structured array, each field of
         # the dtype matches a column
-        converterseq = [_getconv(dt) for dt in dtype_types]
+        converters = [_getconv(dt) for dt in dtype_types]
     else:
         # All fields have the same dtype
-        converterseq = [defconv for i in xrange(N)]
+        converters = [defconv for i in xrange(N)]
 
     # By preference, use the converters specified by the user
-    for i, conv in (converters or {}).iteritems():
+    for i, conv in (user_converters or {}).iteritems():
         if usecols:
             i = usecols.find(i)
-        converterseq[i] = conv
+        converters[i] = conv
 
     # Parse each line, including the first
     for i, line in enumerate(itertools.chain([first_line], fh)):
@@ -348,7 +349,7 @@
             vals = [vals[i] for i in usecols]
 
         # Convert each value according to its column and store
-        X.append(tuple(conv(val) for (conv, val) in zip(converterseq, vals)))
+        X.append(tuple([conv(val) for (conv, val) in zip(converters, vals)]))
 
     if len(dtype_types) > 1:
         # We're dealing with a structured array, with a dtype such as



More information about the Numpy-svn mailing list