Author: bugman Date: Tue Oct 2 18:46:16 2012 New Revision: 17685 URL: http://svn.gna.org/viewcvs/relax?rev=17685&view=rev Log: The relax_io.DummyFileObject now mimics a file object for both Python 2 and 3. In Python 3, everything from a file is of byte type and no longer string type. Modified: trunk/relax_io.py Modified: trunk/relax_io.py URL: http://svn.gna.org/viewcvs/relax/trunk/relax_io.py?rev=17685&r1=17684&r2=17685&view=diff ============================================================================== --- trunk/relax_io.py (original) +++ trunk/relax_io.py Tue Oct 2 18:46:16 2012 @@ -1039,8 +1039,17 @@ def __init__(self): """Set up the dummy object to act as a file object.""" - # Initialise an object for adding the string from all write calls to. - self.data = '' + # Initialise for Python 2. + if py_version == 2: + self.data = '' + self._newline = '\n' + self._empty = '' + + # Initialise for Python 3. + elif py_version == 3: + self.data = b'' + self._newline = b'\n' + self._empty = b'' # Set the closed flag. self.closed = False @@ -1079,15 +1088,15 @@ """ # Split up the string. - lines = self.data.split('\n') + lines = self.data.split(self._newline) # Remove the last line if empty. - if lines[-1] == '': + if lines[-1] == self._empty: lines.pop() # Loop over the lines, re-adding the newline character to match the file object readlines() method. for i in range(len(lines)): - lines[i] = lines[i] + '\n' + lines[i] = lines[i] + self._newline # Return the file lines. return lines