[Numpy-svn] r8201 - trunk/numpy/matrixlib

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 20:46:46 CST 2010


Author: ptvirtan
Date: 2010-02-20 20:46:46 -0600 (Sat, 20 Feb 2010)
New Revision: 8201

Modified:
   trunk/numpy/matrixlib/defmatrix.py
Log:
3K: matrixlib: adapt to changes in str.translate

Modified: trunk/numpy/matrixlib/defmatrix.py
===================================================================
--- trunk/numpy/matrixlib/defmatrix.py	2010-02-21 02:46:29 UTC (rev 8200)
+++ trunk/numpy/matrixlib/defmatrix.py	2010-02-21 02:46:46 UTC (rev 8201)
@@ -6,22 +6,34 @@
 from numpy.core.numerictypes import issubdtype
 
 # make translation table
-_table = [None]*256
-for k in range(256):
-    _table[k] = chr(k)
-_table = ''.join(_table)
-
 _numchars = '0123456789.-+jeEL'
-_todelete = []
-for k in _table:
-    if k not in _numchars:
-        _todelete.append(k)
-_todelete = ''.join(_todelete)
-del k
 
-def _eval(astr):
-    return eval(astr.translate(_table,_todelete))
+if sys.version_info[0] >= 3:
+    class _NumCharTable:
+        def __getitem__(self, i):
+            if chr(i) in _numchars:
+                return chr(i)
+            else:
+                return None
+    _table = _NumCharTable()
+    def _eval(astr):
+        return eval(astr.translate(_table))
+else:
+    _table = [None]*256
+    for k in range(256):
+        _table[k] = chr(k)
+    _table = ''.join(_table)
 
+    _todelete = []
+    for k in _table:
+        if k not in _numchars:
+            _todelete.append(k)
+    _todelete = ''.join(_todelete)
+    del k
+
+    def _eval(astr):
+        return eval(astr.translate(_table,_todelete))
+
 def _convert_from_string(data):
     rows = data.split(';')
     newdata = []



More information about the Numpy-svn mailing list