1. Albert-Jan Roskam
  2. savReaderWriter
  3. Issues
Issue #17 resolved

Python3: AttributeError: 'str' object has no attribute 'decode'

Anonymous created an issue


I am trying out savReaderWriter on python3.3.0 and I've installed the py3k package that was in issue #8 (https://bitbucket.org/fomcl/savreaderwriter/get/py3k.zip) and I get this error while trying to write spss-file: AttributeError: 'str' object has no attribute 'decode' at savWriter.py, line 239 in writerow self._pyWriterow(record) and in line 261 in _pyWriteRow value = template % value.decode(encoding), when for example trying to run wiki's typical use example (at the end of Write Spss system files section).

Comments (3)

  1. Albert-Jan Roskam repo owner


    Yes, the Py3k version is not quite ready yet. That applies in particular to SavWriter, where I stopped coding while messing with the writerow method. I think it is fairly easy to make a working version and I will see if I can (finally!) make some time for this week. String (Python 2) substitution (%s) is not possible with Python 3 bytes objects and I was struggling to find a nice and efficient way to deal with this. Efficiency is especially important for the writerow method, which may be called millions of times. Perhaps I should make two implementations, one for Python 2 and one for Python 3. I hate using "if sys.version_info[0] > 2" in the code too much though!

    Regards, Albert-Jan

    regards, Albert-Jan

  2. Log in to comment