MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/1gk9vz/creating_python_commandline_applications/cal23y7/?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
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
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.
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: