在Windows(32)上使用python 3.5.2,我正在閱讀一個DBF文件,它返回一個OrderedDict。當訪問OrderedDict的記錄時Unicode解碼錯誤
from dbfread import DBF
Table = DBF('FME.DBF')
for record in Table:
print(record)
當訪問的第一個記錄,直到我達到其中包含變音符號記錄一切正常:
Traceback (most recent call last):
File "getdbe.py", line 3, in <module>
for record in Table:
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\dbf.py", line 311, in _iter_records
for field in self.fields]
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\dbf.py", line 311, in <listcomp>
for field in self.fields]
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\field_parser.py", line 75, in parse
return func(field, data)
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\field_parser.py", line 83, in parseC
return decode_text(data.rstrip(b'\0 '), self.encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 11: ordinal not in range(128)
即使我不打印記錄我仍然有問題。
有什麼想法?
https://dbfread.readthedocs.io/en/latest/introduction.html#character-encodings,嘗試傳遞'DBF(...)'正確的編碼。 –
你確定它是UTF-8編碼嗎? – Harrison
@哈里森:我非常懷疑它,DBF不是我期望看到UTF-8編碼數據的格式。 OP甚至提到UTF-8在哪裏? –