mailr17669 - /trunk/relax_io.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 02, 2012 - 15:42:
Author: bugman
Date: Tue Oct  2 15:42:37 2012
New Revision: 17669

URL: http://svn.gna.org/viewcvs/relax?rev=17669&view=rev
Log:
Python 3 fix for the reading of text from a bz2 file.

In Python 3, the readlines() function was returning a list of bytes types, 
not a list of strings.
The relax_io.extract_data() function now detects this and converts to string 
when possible.


Modified:
    trunk/relax_io.py

Modified: trunk/relax_io.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/relax_io.py?rev=17669&r1=17668&r2=17669&view=diff
==============================================================================
--- trunk/relax_io.py (original)
+++ trunk/relax_io.py Tue Oct  2 15:42:37 2012
@@ -150,16 +150,22 @@
     # Create a data structure from the contents of the file split by either 
whitespace or the separator, sep.
     data = []
     for i in range(len(file_data)):
+        # Python 3 support - conversion of bytes type objects to strings.
+        if hasattr(file_data[i], 'decode'):
+            file_data[i] = file_data[i].decode()
+
         if sep:
             row = file_data[i].split(sep)
         else:
             row = file_data[i].split()
         data.append(row)
-    return data
 
     # Close the file.
     if not file_data:
         file.close()
+
+    # Return the data.
+    return data
 
 
 def file_root(file_path):




Related Messages


Powered by MHonArc, Updated Tue Oct 02 16:00:02 2012