Python pickle: fix \r characters before loading

前端 未结 4 2135
予麋鹿
予麋鹿 2021-01-02 13:46

I got a pickled object (a list with a few numpy arrays in it) that was created on Windows and apparently saved to a file loaded as text, not in binary mode (ie. with

4条回答
  •  北海茫月
    2021-01-02 14:22

    Newlines in Windows aren't just '\r', it's CRLF, or '\r\n'.

    Give file.read().replace('\r\n', '\n') a try. You were previously deleting carriage returns that may not have actually been part of newlines.

提交回复
热议问题