Making the fromFile function compatible with psydat files obtained with Python 2 (easy fix)

Hi,
I was trying to load some old .psydat files obtained under python 2 and got the following error:

    contents = pickle.load(f)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 2: ordinal not in range(128)

A simple fix consists in adding the argument encoding=‘latin1’ line 55 of the filetools.py:

        with open(filename, 'rb') as f:
            contents = pickle.load(f, encoding='latin1')

Might be good to correct this in future versions (sorry if it has been corrected in new versions).
All the best,
Mat

Yes. Maybe do this with a try…except on the UnicodeDecodeError so that existing loads also work (I don’t think Latin1 will work universally, only for old files).

Do you want to submit a Pull Request?

Done

1 Like