I’d argue that using argh
is just as easy and strictly better:
$ cat test.py
#!/usr/local/bin/python
import argh
def start(width, depth, height):
print(float(width) * float(depth) * float(height))
if __name__ == '__main__':
p = argh.ArghParser()
p.set_default_command(start)
p.dispatch()
$ ./test.py -h
usage: test.py [-h] width depth height
positional arguments:
width -
depth -
height -
options:
-h, --help show this help message and exit
$ ./test.py 1 2 3
6.0
$ ./test.py 1 2 3 4
usage: test.py [-h] width depth height
test.py: error: unrecognized arguments: 4
$ ./test.py 1 2
usage: test.py [-h] width depth height
test.py: error: the following arguments are required: height
And it’s even easier if you are willing to use commands (which is often useful when you want to extend the script to do more than one thing):
$ cat test.py
#!/usr/local/bin/python
import argh
def volume(width, depth, height):
print(float(width) * float(depth) * float(height))
def area(width, height):
print(float(width) * float(height))
if __name__ == '__main__':
argh.dispatch_commands([volume, area])
$ ./test.py -h
usage: test.py [-h] {volume,area} ...
positional arguments:
{volume,area}
volume
area
options:
-h, --help show this help message and exit
$ ./test.py volume -h
usage: test.py volume [-h] width depth height
positional arguments:
width -
depth -
height -
options:
-h, --help show this help message and exit
$ ./test.py volume 1 2 3
6.0
$ ./test.py area 12 24
288.0
It will certainly come with calls for content moderation, but for all the reasons you allude to, the assertion that there will be a need for such moderation seems quite tendentious.