Python平面文件解析器

时间:2018-06-29 02:32:04

标签: python json utf-8 utf-16

我正在尝试使用此存储库(https://github.com/schirinos/nutrient-db)来解析USDA的营养数据库。 但是,我无法克服一些问题

  1. python3 Nutritiondb.py -e> Nutritions.py

上面的代码行抛出以下错误

traceback (most recent call last):

File "nutrientdb.py", line 355, in <module>

main()

File "nutrientdb.py", line 332, in main

nutrients.refresh(path + 'FOOD_DES.txt', 'food_des')

File "nutrientdb.py", line 278, in refresh

for line in f:

File "/Users/benyam/anaconda3/lib/python3.6/codecs.py", line 321, in 
decode

(result, consumed) = self._buffer_decode(data, self.errors, final)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x91 in position 
4009: invalid start byte
  1. 我已经使用python 2.7(原始文件的默认设置)创建了Nutritions.json,并尝试将文件加载到json中,并引发以下错误:

    Traceback (most recent call last):
    
    File "<stdin>", line 2, in <module>
    File
    File
    "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
    json/__init__.py", line 339, in loads
    
    return _default_decoder.decode(s)
    
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/
    python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    
     File
     "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
     /json/decoder.py", line 382, in raw_decode
     raise ValueError("No JSON object could be decoded")
     ValueError: No JSON object could be decoded
    

我现在的问题是,如何确定解析器内部导致此问题的代码行,即Nutritiondb.py?还有什么解决办法?

0 个答案:

没有答案