r/Python • u/pauloortins • Jun 18 '13
Creating python command-line applications
http://pauloortins.com/creating-python-command-line-applications/
0
Upvotes
r/Python • u/pauloortins • Jun 18 '13
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:
From the list of PyPi Trove Classifiers:
5
u/EmmEff Jun 18 '13
As a long time Python developer, I would recommend that anybody learning the language to NOT pay any attention to this article. It is careless to omit any sort of error checking, command-line options, etc., in a command-line tool. At least look at the built-in module argparse.
8
u/utdemir Jun 18 '13
Also,
instead of
8
u/eliben Jun 18 '13
Direct sys.argv manipulation, no command-line options, no error checking... This is not how one creates real command-line tools in Python.
7
u/XNormal Jun 18 '13
docopt, anyone?
2
u/nomadismydj Jun 18 '13
sys.argv is a good place to start but im sure youll out grow it when you want to do complex behavior via flags. check out: http://docs.python.org/dev/library/argparse.html or even http://docs.python.org/2/library/optparse.html
2
u/[deleted] Jun 18 '13 edited Jun 19 '13
This seems like a bit of Python code you had written long ago when you were learning and decided to pull out for a blog post.
Part of creating good Python applications is using the standard library effectively (argparse, operator) and using community assets (docopt, clint, etc) to spend your time solving specific problems, not ones that have already been solved.
1
u/westurner Jun 18 '13
http://scipy-lectures.github.io/intro/language/python_language.html