Unpickle patch: cannot instantiate 'WindowsPath' on your system

edgar at openmail.cc edgar at openmail.cc
Wed Oct 23 14:43:58 EDT 2019


Hello,

I hope that I am writing to the right list.
Python 3.7.4 on GNU/Linux Parabola 5.3.1-gnu-1 x86_64 AMD

Issue:
I got a .pickle which had some WindowsPath inside. I was unable to 
unpickle like this:

┌────
│ import pickle as pkl
│ from pathlib import Path, PureWindowsPath, PurePath, PurePosixPath, 
WindowsPath, PosixPath
│ fname = "ohw_analysis.pickle"
│ # fpath = PureWindowsPath(fname)
│ fpath = Path(fname)
│ with open(fpath, "rb") as fd:
│     # Works in Winbug$ only
│     ohw_analysis = pkl.load(fd)
└────

I tried to create my own class to override =_new= in =Path=, but that 
did not work, because (I assume that) the pickle data was pointing to 
=pathlib=. I did not know how to solve this, so I modified the code for 
pathlib.py

Solution:
The modification allowed me to unpickle the file, and I think that it 
would not break =pathlib=. I have seen this issue reported elsewhere, 
and I thought that it could be useful to others.

Extra:
I really hope that this is useful. Although I am not asking for help, if 
there was a better solution, let me know. I don't want a Github account 
(Micro$oft).

Thanks!


More information about the Python-list mailing list