Creating a Terminal Program with Python

后端 未结 5 1638
情歌与酒
情歌与酒 2021-01-30 05:39

I recently started learning python. I have created some basic webapps with Django and wrote some simple scripts. After using VIM as a Python IDE I really fell I love with \"Term

5条回答
  •  感情败类
    2021-01-30 06:13

    THe simplest way to do an interactive console application would be:

    while True:
        command = raw_input('command? ').strip()
        if command == 'say_hello':
            print('Hello')
        elif command == 'other_thing':
            print('Doing something else')
        elif command == 'quit':
            break
        else:
            print('Invalid Command.')
    

    That's the basic structure. If you want something more vim-like, you'll probably need to use the curses library.

提交回复
热议问题