Python 如何处理来自控制台应用程序的密钥

Python 如何处理来自控制台应用程序的密钥,python,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 f

我正在使用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

对于您的目标,您可以查看模块,它是为历史处理等事项而设计的。它是标准的python库,因此可以满足您的需要。使用其他模块,您甚至可以处理自动完成。

这是谁编辑的?:|这是无效的python代码:-/是否需要跨平台?如果没有,在哪个站台?