Windows下VIM使用Pyclewn的Unicode Decode Error

最近在轉VIM, 又不想裝linux(我手提裝Ubuntu70+度.. win7 50+度.)... 所以搞到麻煩重重... 經常有些莫名其妙的問題出來.. 很多問題往往google一下就可以... 這個Pyclewn卻死活無解.... 無奈之下 只好親手尋根朔源.. 

本文環境:

Windows7 SP2

VIM 7.3 1-46 

Python32

Pyclewn-1.6.py3.win32

在大部分目錄... 有如下錯誤.

class<UnicodeDecodeError>
 'utf8' codec can't decode byte 0xd3 in position 0: invalid continuation byte
...  xxx ... xxx gdb.py:235


有類似以上提示.. 很明顯. 問題出現在 Python32\Lib\site-packages\clewn\ 目錄下 gdb.py 文件, 一個Decode問題.

於是VIM進去看了下源碼..

在第235發現如下:

    return result.decode()

於是改啊改..

latin_1

windows-1252

最後.. 用 GBK編碼就OK了.

return result.decode("GBK")



本文夠水吧... 此問題應該也有人會遇到吧. 

发布了57 篇原创文章 · 获赞 13 · 访问量 7万+
展开阅读全文

UnicodeDecodeError: 'gbk' codec can't decode byte

11-11

运行 "Learn Python the Hard Way" 里的代码时出现的报错。代码: ``` 1. from sys import argv 2. from os.path import exists 3. 4. script, from_file, to_file = argv 5. 6. print(f"Copying from {from_file} to {to_file}") 7. 8. # we could do these two on one line, how? 9. in_file = open(from_file) 10. indata = in_file.read() 11. 12. print(f"The input file is {len(indata)} bytes long") 13. 14. print(f"Does the output file exsit? {exists(to_file)}") 15. print("Ready, hit RETURN to continue, CTRL-C to abort.") 16. input() 17. 18. out_file = open(to_file, 'w') 19. out_file.write(indata) 20. 21. print("Alright, all done.") 22. 23. out_file.close() 24. in_file.close() ``` 照抄书本在 Terminal 上输入的命令: $ echo "This is a test file." > test.txt $ cat test.txt This is a test file. $ python ex17.py test.txt new_file.txt 下面是 Terminal 给的提示: Copying from test.txt to new_file.txt Traback ( most recent call last): File "ex17.py", line 10, in <module> indata = in_file.read() UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence 尝试把 'gbk' 编码改为 'UTF-8': 9. in_file = open(from_file, 'r', encoding = 'UTF-8') Terminal 给出的提示 Copying from test.txt to new_file.txt Traceback (most recent call last): File "ex17.py", line 10, in <Module> indata = in_file.read() File "C:\Python36\lib\codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 求解:是什么导致这个 Error ?以及如何解决? 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览