Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
368
|
10 章 檔案與文字作業
getch, getche getch() getche()
從鍵盤輸入讀取並回傳一個字元,若尚無字元可讀取,就等候。
getche
還會將該字元回應(echo)到螢幕上(若是可列印的),而
getch
會。當使用者按下一個特殊鍵(方向鍵、功能鍵等),它會被視為兩個
字元:先是一個
chr(0)
chr(224)
,然後是與第一個字元一起定義了
使用者所按下的特殊鍵的第二個字元。要找出
getch
會為任意鍵回傳什
麼,就在 Windows 機器上執行下列這一小段指令稿:
import msvcrt
print("press z to exit, or any other key
to see the key's code:")
while True:
c = msvcrt.getch()
if c == 'z': break
print('{} ({!r})'.format(ord(c), c))
kbhit kbhit()
當有一個字元可供讀取,就回傳
True
(這時呼叫
getch
會即刻回傳),
否則為
False
(這時呼叫
getch
就會等候)。
ungetch ungetch(c)
Ungets(放回)」字元
c
;對
getch
getche
的下次呼叫會回傳
c
連續呼叫
ungetch
兩次,而且其間沒有中介的
getch
getche
呼叫,就
會是錯誤。
互動式的命令工作階段
cmd
模組提供了一種簡單的方式來處理命令(commands)的互動式工作
階段(interactive sessions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819