2017-11-16 7 views
0

私のMAC OSに完全にロードする.pklファイルがありますが、Windowsマシンではロードされません。私はanacondaでpython 3を使用しています。 これは私のコードです:Windows OSを使用して.pklファイルからデータを取得する方法

data=pickle.load(open("ydata1.pkl",'rb'))

エラー:UnicodeDecodeError: 'ASCII' コーデックが位置2295でのバイト0xc3をデコードすることはできません。

:ない範囲で序(128)

は、だから私はこれを試してみました

data=pickle.load(open("ydata1.pkl",'r'))

しかし、私はというエラーを取得:バイトのようなオブジェクトが必要な、ない「str」は

は、誰も私が間違っているつもりですどこを教えていただけますか?モードRBと

答えて

0

使用open()

ドキュメントから撮影
import pickle 

with open('ydata1.pkl', 'rb') as p_f: 
    data = pickle.load(f) 

Pickle incompatability of numpy arrays between Python 2 and 3

https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

On Windows, 'b' appended to the mode opens the file in binary mode, so there are also modes like 'rb', 'wb', and 'r+b'. Python on Windows makes a distinction between text and binary files; the end-of-line characters in text files are automatically altered slightly when data is read or written. This behind-the-scenes modification to file data is fine for ASCII text files, but it’ll corrupt binary data like that in JPEG or EXE files. Be very careful to use binary mode when reading and writing such files. On Unix, it doesn’t hurt to append a 'b' to the mode, so you can use it platform-independently for all binary files.

また、あなたは、Python 2/Pythonの3つのピクルスの互換性の問題を抱えていないことを確認してください

関連する問題