MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/1gk9vz/creating_python_commandline_applications/cal19xx/?context=3
r/Python • u/pauloortins • Jun 18 '13
20 comments sorted by
View all comments
10
https://en.wikipedia.org/wiki/Command-line_interface
https://en.wikipedia.org/wiki/Command-line_argument_parsing#Python
https://en.wikipedia.org/wiki/Python_(programming_language)
Automated testing is much easier when there is a main function.
main
Minimally, in Unix style:
def main(): '''Prints "Hello World!"''' print("Hello world!") return 0 if __name__ == '__main__': import sys sys.exit(main())
http://docs.python.org/2.6/library/optparse.html
http://docs.python.org/2.7/library/argparse.html
http://docs.python.org/3/library/argparse.html
From the list of PyPi Trove Classifiers:
Environment :: Console
7 u/ScriptSimian Jun 18 '13 I was going to post argparse. Building a CLI as suggested is error prone and not to be undertaken except for didactic purposes. 4 u/westurner Jun 18 '13 http://pythonhosted.org/argh/ 1 u/pauloortins Jun 18 '13 Agree, the best way is using optparse or argparse =D 3 u/abledanger Jun 18 '13 Just found optparse yesterday, even though it's a standard library. It's awesome. 10 u/nemec Jun 18 '13 optparse is deprecated, I'd stick to argparse (which is brilliant, IMO). (for proof, check out the 2.7 docs) 2 u/talideon Jun 18 '13 Or better yet: docopt. 3 u/justdweezil Jun 18 '13 Baker and Commandr both make CLI programming trivial:https://pypi.python.org/pypi/Baker/ https://pypi.python.org/pypi/commandr/1.0.1
7
I was going to post argparse. Building a CLI as suggested is error prone and not to be undertaken except for didactic purposes.
argparse
4 u/westurner Jun 18 '13 http://pythonhosted.org/argh/ 1 u/pauloortins Jun 18 '13 Agree, the best way is using optparse or argparse =D
4
http://pythonhosted.org/argh/
1
Agree, the best way is using optparse or argparse =D
3
Just found optparse yesterday, even though it's a standard library. It's awesome.
10 u/nemec Jun 18 '13 optparse is deprecated, I'd stick to argparse (which is brilliant, IMO). (for proof, check out the 2.7 docs) 2 u/talideon Jun 18 '13 Or better yet: docopt.
optparse is deprecated, I'd stick to argparse (which is brilliant, IMO). (for proof, check out the 2.7 docs)
2 u/talideon Jun 18 '13 Or better yet: docopt.
2
Or better yet: docopt.
Baker and Commandr both make CLI programming trivial:
https://pypi.python.org/pypi/Baker/ https://pypi.python.org/pypi/commandr/1.0.1
10
u/westurner Jun 18 '13
https://en.wikipedia.org/wiki/Command-line_interface
https://en.wikipedia.org/wiki/Command-line_argument_parsing#Python
https://en.wikipedia.org/wiki/Python_(programming_language)
Automated testing is much easier when there is a
mainfunction.Minimally, in Unix style:
http://docs.python.org/2.6/library/optparse.html
http://docs.python.org/2.7/library/argparse.html
http://docs.python.org/3/library/argparse.html
From the list of PyPi Trove Classifiers: