[問題] readchar module遇到UnicodeDecodeError
各位前輩好,最近剛開始學習Python (使用3.5版本)
目前開發了一個小程式,並用pyinstaller打包成exe給其他同事使用
exe執行時會show出一些訊息,但執行結束後console會自動關閉,導致訊息看不到
所以想在程式最後加入類似C語言的getch()功能
讓使用者敲下任意鍵後再關閉console
上網搜尋到了readchar module (https://github.com/magmax/python-readchar)
並在程式最後放了程式碼如下:
print("Press any key to exit.")
a = readchar.readchar()
quit()
但執行時碰到UnicodeDecodeError,詳細錯誤訊息如下:
Traceback (most recent call last):
File "C:\Python\code\RD1607_OTA\exe_test\ota_package.py", line 47, in
<module>
a = readchar.readchar()
File "C:\Python\Python35\lib\site-packages\readchar\readchar_windows.py",
line 23, in readchar
while ch.decode(win_encoding) in XE0_OR_00:
UnicodeDecodeError: 'mbcs' codec can't decode bytes in position 0--1: No
mapping for the Unicode character exists in the target code page.
不知道是否是我的環境在設定上出了什麼問題,
還是其實有更簡單的方式達到我想要的功能呢?
先謝過各位前輩了!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.73.120.86
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1533780953.A.45F.html
→
08/09 11:51,
5年前
, 1F
08/09 11:51, 1F
→
08/09 14:00,
5年前
, 2F
08/09 14:00, 2F
→
08/09 20:56,
5年前
, 3F
08/09 20:56, 3F
→
08/10 06:39,
5年前
, 4F
08/10 06:39, 4F
→
08/10 06:41,
5年前
, 5F
08/10 06:41, 5F
→
08/10 06:41,
5年前
, 6F
08/10 06:41, 6F
推
08/11 01:14,
5年前
, 7F
08/11 01:14, 7F
→
08/11 01:14,
5年前
, 8F
08/11 01:14, 8F
→
08/11 01:15,
5年前
, 9F
08/11 01:15, 9F