我正在使用 hfcca 计算 C++ 代码的圈复杂度。 hfcca 是一个简单的 python 脚本 ( https://code.google.com/p/headerfile-free-cyclomatic-complexity-analyzer/ )。当我尝试运行脚本以生成 xml 文件形式的输出时,出现以下错误:
Traceback (most recent call last):
"./hfcca.py", line 802, in <module>
main(sys.argv[1:])
File "./hfcca.py", line 798, in main
print(xml_output([f for f in r], options))
File "./hfcca.py", line 798, in <listcomp>
print(xml_output([f for f in r], options))
File "/x/home06/smanchukonda/PREFIX/lib/python3.3/multiprocessing/pool.py", line 652, in next
raise value
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 434852: invalid continuation byte
请帮我解决这个问题..
最佳答案
问题看起来是文件中包含用 latin1 表示的字符,这些字符不是 utf8 中的字符。 file
实用程序可用于确定应将文件视为何种编码,例如:
monk@monk-VirtualBox:~$ file foo.txt
foo.txt: UTF-8 Unicode text
这是字节在 latin1 中的含义:
>>> b'\xe2'.decode('latin1')
'â'
可能最简单的方法是将文件转换为 utf8。
关于python - Unicode解码错误: 'utf-8' codec can't decode byte 0xe2 in position 434852: invalid continuation byte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16148356/