https://stackoverflow.com/questions/35879096/pickle-unpicklingerror-could-not-find-mark
_pickle.UnpicklingError: could not find MARK
I got exceptions like UnicodeDecodeError raised when pickling (a list of) objects of EventFrame with a member participants that was an empty set. class EventFrame: """Frame for an event""" ...
stackoverflow.com
The error _pickle.UnpicklingError: could not find MARK is raised because the offset of the file is not in the beginning. The solution is to call f.seek(0) before loading the pickle.
파일의 offset이 파일의 맨 앞에 있지 않아 발생하는 오류
solution: pickle 로딩 전에 f.seek(0) 써주기
f 는 파일 객체
seek() 기본 형태
f.seek(offset, 기준점)
offset
기준점으로부터의 앞 뒤 바이트 수 나타냄
- 양수는 뒤쪽으로, 음수면 앞쪽으로 이동
기준점
0: 파일의 맨 앞으로 이동
다시 읽기 모드(r)에서는 처음부터 읽을 준비
쓰기 모드(w)에서는 앞쪽에 쓰는 것
1: 현재 위치
(자주 쓰지는 않음)
2: 파일의 맨 끝으로 이동
- r 에서는 더 이상 읽을 게 없다는 것 의미
- w 에서는 이어쓰기(a)가 됨
a 모드가 아니라 r+ 모드에서 파일에 내용 추가하려면,
파일 읽어온 후에 반드시 파일 포인터를 끝으로 옮겨주고 입력해야 함