[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unpickle patch: cannot instantiate 'WindowsPath' on your system


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

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

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.

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