Outils pour utilisateurs

Outils du site


python:selection_liste_de_choix

Sélection dans une liste de choix

Sélectionner une commande à exécuter parmi une liste affichée à l'écran :

#!/usr/bin/env python3
 
import os
 
commands = {
    '1': "ligne de commande 1",
    '2': "ligne de commande 2",
    '3': "ligne de commande 3",
}
 
for key in commands:
    print("%-3s: %s" % (key, commands[key]))
 
choice = input("Commande à exécuter: ")
 
if(commands[choice]):
    os.system(commands[choice])
python/selection_liste_de_choix.txt · Dernière modification: 2020/08/16 04:51 par marclebrun