UnicodeDecodeError가 발생한 위치를 어떻게 알 수 있습니까? here 이상의 자료를 발견했으며이를 아래에서 구현하려고했습니다. 하지만 난 그냥 오류가 발생합니다 NameError: name 'err' is not defined
UnicodeDecodeError가 발생한 위치를 얻는 방법은 무엇입니까?
인터넷을 통해 이미 여기저기서 StackOverflow를 검색했지만 사용 방법을 찾을 수 없습니다. 파이썬 워드 프로세서에서는이 특별한 예외가 시작 속성을 가지고 있으므로 가능해야한다고 말합니다.
감사합니다.
data = buffer + data
try:
data = data.decode("utf-8")
except UnicodeDecodeError:
#identify where did the error occure?
#chunk that piece off -> copy troubled piece into buffer and
#decode the good one -> then go back, receive the next chunk of
#data and concatenate it to the buffer.
buffer = err.data[err.start:]
data = data[0:err.start]
data = data.decode("utf-8")
투표에 당신은
as
키워드로 예외 객체를 취득하고,start
속성을 사용할 수 있습니다 닫기로 사소한 '사촌 대답은 필수적인 구문 세부 사항입니다. 나중에 참조 할 때 유용 할 수 있습니다. –