[dataio] Don't assume by default the input of ``autocasted`` is a string.
authorSimon Chabot <simon.chabot@logilab.fr>
Thu, 29 Nov 2012 14:11:20 +0100
changeset 169 2ca1f2b23577
parent 168 05d434a3c728
child 170 3679c8eab2be
[dataio] Don't assume by default the input of ``autocasted`` is a string. The argument of ``autocasted`` may be an int or a float or whatever and those types don't have a ``strip`` method. So the idea is to call this method only if it's neither a float nor an int.
dataio.py
--- a/dataio.py	Mon Nov 26 11:52:28 2012 +0100
+++ b/dataio.py	Thu Nov 29 14:11:20 2012 +0100
@@ -24,13 +24,13 @@
     """ Try to convert data into a specific type
     in (int, float, str)
     """
-    data = data.strip()
     try:
         return int(data)
     except ValueError:
         try:
             return float(data.replace(',', '.'))
         except ValueError:
+            data = data.strip()
             if encoding:
                 return data.decode(encoding)
             return data