如何从控制台应用程序处理密钥

2024-03-29 10:01:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是python2.6,我想知道如何从控制台使用up键。 我现在不想使用Tkinter或其他GUI库。你知道吗

下面是我的代码。你知道吗

history=[]    
while(1): 
    try:
        cmd = self.get_cmd()
        history.append(cmd)   # append user command
        # if i press UP key, just display history. 
        # i'll you for statement to disaply history.
        print "%s" %history

Tags: 代码selfcmdgetiftkinterguihistory
1条回答
网友
1楼 · 发布于 2024-03-29 10:01:24

对于您的目标,您可以查看readline模块,它是为历史处理之类的事情而设计的。它是标准的python库,所以可以满足您的需要。对于其他模块,rlcompleter您甚至可以处理自动完成。你知道吗

相关问题 更多 >