2017-11-16 9 views
0

내 MAC OS에서 완벽하게로드되는 .pkl 파일이 있지만 Windows 컴퓨터에서로드되지 않습니다. 아나콘다에서 파이썬 3을 사용하고 있습니다.Windows OS를 사용하여 .pkl 파일에서 데이터를 가져 오는 방법

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

오류 : 이 내 코드입니다 UnicodeDecodeError '아스키'코덱이 위치 2295 년 바이트 0xc3를 디코딩 할 수 없습니다

: 범위 내에 있지 서수 (128)

그래서 나는이 시도

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

하지만 오류 말하는 얻을하십시오 바이트와 같은 객체가, 내가 잘못 가고 어디

사람이 말해 주시겠습니까 'STR'하지 필요하다? 모드 RB와

답변

0

사용 open()는 : 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.

것은 확실히 당신이 파이썬 2/파이썬 3 피클 호환성 문제가되지 않습니다합니다

import pickle 

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

문서에서 발췌