作者piliGTcat (貍貓)
看板Python
標題[問題] readchar module遇到UnicodeDecodeError
時間Thu Aug 9 10:15:49 2018
各位前輩好,最近剛開始學習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
→ KSJ: input() ?? 08/09 11:51
→ renshin: a=input("Press enter to exit") 但這個無法任意鍵 08/09 14:00
→ s860134: 用cmd 執行你的執行檔 即可留下錯誤資訊 08/09 20:56
→ piliGTcat: 謝謝K大 & r大,目前的確是用input代替 08/10 06:39
→ piliGTcat: s大是指請使用者用cmd執行exe嗎?他們很懶的,不愛key 08/10 06:41
→ piliGTcat: 指令…… 08/10 06:41
推 niceallen: 在打包exe時 default指令 視窗不會關閉才對吧 08/11 01:14
→ niceallen: pyinstaller *.py 08/11 01:14
→ niceallen: 你下了-w ? 08/11 01:15