python3.7+pycharm写一个测试代码读取DBF文件UnicodeDecodeError: 'ascii' codec can't decode by

孩儿的爹 2018-12-11 10:01:56
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from dbfread import DBF
table = DBF("jj.DBF")
for record in table:
for field in record:
print(field, "=", record[field], end = ",")
print()


python3.7+pycharm写一个测试代码读取DBF文件,结果报如下错误。就是一直卡在这个编码上面。求大神指点!!!!!!

D:\Python37\python.exe D:/untitled/text.py
Traceback (most recent call last):
File "D:/untitled/text.py", line 6, in <module>
for record in table:
File "D:\Python37\lib\site-packages\dbfread\dbf.py", line 316, in _iter_records
for field in self.fields]
File "D:\Python37\lib\site-packages\dbfread\dbf.py", line 316, in <listcomp>
for field in self.fields]
File "D:\Python37\lib\site-packages\dbfread\field_parser.py", line 79, in parse
return func(field, data)
File "D:\Python37\lib\site-packages\dbfread\field_parser.py", line 87, in parseC
return self.decode_text(data.rstrip(b'\0 '))
File "D:\Python37\lib\site-packages\dbfread\field_parser.py", line 45, in decode_text
return decode_text(text, self.encoding, errors=self.char_decode_errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xca in position 0: ordinal not in range(128)

Process finished with exit code 1
...全文
396 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_43864604 2018-12-16
  • 打赏
  • 举报
回复
我使用os.system执行参数带中文的命令也出现了这样的错误提示?有同学遇到过吗?
H_orizon 2018-12-12
  • 打赏
  • 举报
回复
from dbfread import DBF table = DBF("jj.DBF", encoding = 'gbk') for record in table: for field in record: print(field, "=", record[field], end = ",") print()
zarelaky 2018-12-11
  • 打赏
  • 举报
回复
https://dbfread.readthedocs.io/en/latest/dbf_objects.html
里面有参考,可以看看DBF文件里面对应field用的是什么编码,改一下encoding的设置

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧