这是预期的行为吗(如果是的话,有人可以解释为什么)? 这只会发生在使用Dill,而不是pickle.
from pathlib import Path
import dill
class MyClass:
def __init__(self) -> None:
pass
path = Path('test/test.pkl')
# create parent directory if it does not exist
path.parent.mkdir(exist_ok=True)
x = [ MyClass() ]
dill.dump(x, path.open('wb'))
y = dill.load(path.open('rb'))
print(isinstance(x[0], MyClass)) # True
print(isinstance(y[0], MyClass)) # False ???
我以为是True
块.