console user interface
while True:
option = input('Show me what u want')
if option == OPTION1:
...
elif option == OPTION2:
...
elif option == 'q':
break
else:
print(f'{option} is not supported')
import inquirer
questions = [
inquirer.Text('name', message="What's your name"),
inquirer.Text('surname', message="What's your surname"),
inquirer.Text(
'phone', message="What's your phone number",
validate=lambda _, x: re.match('\+?\d[\d ]+\d', x),
)
]
answers = inquirer.prompt(questions)
command line interface
&> cat requirements.txt
jupyterlab
ipython>=7.23.1
flake8
PyQt5
&> ls -l
requirements.txt
source_stats.py
&> grep -i pyqt requirements.txt
PyQt5
&> tar --list -f NSimulator.tar
&> python some_script.py arg1 arg2
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'-q', '--quiet',
action='store_true',
dest='quiet',
help='Suppress Output'
)
args = parser.parse_args()
print(f'Quiet mode is {args.quiet}.')
&> python some_script.py -h
...
&> python some_script.py -q
Quiet mode is True.
parser = argparse.ArgumentParser()
parser.add_argument(
'-r', '--range', default=[1-100], dest='range',
type=int, nargs=2,
)
args = parser.parse_args()
print(
f'Number I got are: '
f'{list(range(*args.range))}.'
)
&> python some_script.py --range 14 17
The defined range is [14, 15, 16].
&> python some_script.py --range 14 kek
usage: some_script.py [-h] [-r RANGE RANGE]
scratch_22.py: error: argument -r/--range:
invalid int value: 'kek'
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'--color',
choices=('blue', 'black', 'brown'),
dest='color', default='blue',
)
args = parser.parse_args()
print(f'You have chosen {args.color}.')
&> python some_script.py --color blue
You have chosen blue.
&> python some_script.py --color red
usage: some_script.py [-h] [--color {blue,black,brown}]
scratch_22.py: error: argument --color: invalid choice:
'red' (choose from 'blue', 'black', 'brown')
argparse: subparsers
&> git pull
...
&> git push
...
&> git branch
...
graphical user interface