
21.10.20 05:05, Michael Smith пише:
There are many ways to invoke a function from the commandline. You can use setuptools' console_scripts entrypoint. You can use a decorator from click. And of course you can always do the classic
if __name__ == "__main__": main()
to call whatever main() is. But there are inconveniences with these approaches. For setuptools, you have to actually run setup, somehow. For click, you have to install click. And for __name__, you are either locked into a single function name, or you have to write some arg parsing to determine what name to use.
I propose it would be nice to be able to call a function from python, using syntax like
python -m module:thunk
Currently you can do this using packages. Convert module into package, make the thunk subdirectory, and write you code into module/thunk/__main__.py. Invoking "python -m module.thunk" will execute that code. Invoking "python -m module" will execute the code in module/__main__.py.