[問題] readchar module遇到UnicodeDecodeError

看板Python作者 (貍貓)時間5年前 (2018/08/09 10:15), 編輯推噓1(108)
留言9則, 5人參與, 5年前最新討論串1/1
各位前輩好,最近剛開始學習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
input() ??
08/09 11:51, 1F

08/09 14:00, 5年前 , 2F
a=input("Press enter to exit") 但這個無法任意鍵
08/09 14:00, 2F

08/09 20:56, 5年前 , 3F
用cmd 執行你的執行檔 即可留下錯誤資訊
08/09 20:56, 3F

08/10 06:39, 5年前 , 4F
謝謝K大 & r大,目前的確是用input代替
08/10 06:39, 4F

08/10 06:41, 5年前 , 5F
s大是指請使用者用cmd執行exe嗎?他們很懶的,不愛key
08/10 06:41, 5F

08/10 06:41, 5年前 , 6F
指令……
08/10 06:41, 6F

08/11 01:14, 5年前 , 7F
在打包exe時 default指令 視窗不會關閉才對吧
08/11 01:14, 7F

08/11 01:14, 5年前 , 8F
pyinstaller *.py
08/11 01:14, 8F

08/11 01:15, 5年前 , 9F
你下了-w ?
08/11 01:15, 9F
文章代碼(AID): #1RQwFPHV (Python)