-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs04types.py
More file actions
21 lines (17 loc) · 992 Bytes
/
args04types.py
File metadata and controls
21 lines (17 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
import argparse
def info(name, x):
return '{0:15s}:{1} is a {2}'.format(name, x, type(x).__name__)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='a very simple app with command line arguments.')
parser.add_argument('-u', '--upper', action='store_true', help="convert strings to upper case if present - default off")
parser.add_argument('-s', '--set_false', action='store_false', help='this argument defaults to True')
# there are other actions - see https://docs.python.org/3/library/argparse.html#action
parser.add_argument('last', nargs='+', type=float, help='the last argument, zero or more')
# use nargs='+' to force at least 1
# use nargs='*' for zero or more
# use nargs=5 for exactly 5
args = parser.parse_args()
print(info('upper', args.upper))
print(info('set_false', args.set_false))
print(info('last', args.last))