File: example10.py

package info (click to toggle)
python-plac 1.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 620 kB
  • sloc: python: 2,185; lisp: 57; makefile: 30; sh: 20
file content (24 lines) | stat: -rw-r--r-- 651 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# example10.py
import plac


# example with full annotations (help, kind, abbrev, type, choices, metavar)
@plac.annotations(
    operator=("The name of an operator", 'positional', None, str,
              ['add', 'mul']),
    numbers=("Zero or more numbers", 'positional', None, float, None, 'n'))
def main(operator, *numbers):
    "A script to add and multiply numbers"
    if operator == 'mul':
        op = float.__mul__
        result = 1.0
    else:  # operator == 'add'
        op = float.__add__
        result = 0.0
    for n in numbers:
        result = op(result, n)
    return result


if __name__ == '__main__':
    print(plac.call(main))