1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# example10.py
import plac
@plac.annotations(
operator=("The name of an operator", 'positional', None, str, ['add', 'mul']),
numbers=("A number", 'positional', None, float, None, "n"))
def main(operator, *numbers):
"A script to add and multiply numbers"
op = getattr(float, '__%s__' % operator)
result = dict(add=0.0, mul=1.0)[operator]
for n in numbers:
result = op(result, n)
return result
if __name__ == '__main__':
print(plac.call(main)[0])
|