MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/1gk9vz/creating_python_commandline_applications/cal5hzc/?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. 1 u/pauloortins Jun 18 '13 Agree, the best way is using optparse or argparse =D
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
1 u/pauloortins Jun 18 '13 Agree, the best way is using optparse or argparse =D
1
Agree, the best way is using optparse or argparse =D
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: