Skip to content
Custom command for Input functions
Profile icon
[deleted]

Heya, I'm trying to make an application in Python. Do you know how I can make it so, if someone types /exit in any input, it shuts down? I already know how to make it shut down by using the os package...

import os os.system('exit')

All I need to do is add that "command" for all inputs. I just need a simpler way instead of adding "if input = "\exit" then os.system('exit')" all the time.

Any help is appreacited!

You are viewing a single comment. View All
Profile icon
Coder100
def exit(): # Code here commands = { "exit": exit } # Get command command = input("command> ") # Loop through dict for key in commands: # Check if key == user input if key == command: # run the command commands[key]()

Hopes this helps!


@zinxcode