Python pickle: fix \r characters before loading

后端 未结 4 1277
清歌不尽
清歌不尽 2021-01-02 14:41

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 15:14

    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.

提交回复
热议问题