On Jul 30, 2019, at 15:21, firstname.lastname@example.org wrote:
Maybe the def __main__() argument is already a dead horse, given the number of discussions it has created that have ended nowhere, but I think one argument in favour of its implementation would be including argument parsing in it, for example:
def __run__(first_num, second_num, print_operation=False):
Couldn’t you get nearly the same effect in Python today just by adding one line:
That doesn’t do any fancy parsing of the arguments, but, except for the -h magic, neither does your proposal.
$ python main.py -h
Does —help also work? (It’s pretty weird that you use a long arg for verbose but a short arg for help.)
$ python main.py 1 2 --verbose 1 + 2 = 3
But if I run the same thing in the more traditional way:
$ python main.py —verbose 1 2
… I’ll get an error, because the first argument isn’t an int and can’t be added to 1.
$ python main.py 1 2 —quiet
… does the same thing as —verbose, which is pretty misleading.
Not that I haven’t done the quick hacky “this script isn’t going to be used by anyone but me, and only for the next two days, and it only needs one flag, so just assume any third arg is that flag” thing. But that’s hardly something you want a language feature to actively encourage.
There are lots of great third-party libraries that make turning a function into a command-line utility a lot easier than using argparse. I think whenever you want anything more than argv and don’t want argparse, you should probably just use one of those libraries.