Differences between revisions 12 and 17 (spanning 5 versions)
Revision 12 as of 2009-05-30 18:08:46
Size: 1574
Editor: bas3-kingston08-1168067989
Comment: Add link to an example Python shell script
Revision 17 as of 2021-02-07 21:57:21
Size: 2141
Editor: IwanAucamp
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
'''Creating Command Line Tools With Python''' == Creating Command Line Tools With Python ==
Line 3: Line 3:
=== Standard library support for parsing command lines ===
Line 4: Line 5:
 * [[https://docs.python.org/library/optparse.html|optparse]] and [[https://docs.python.org/library/argparse.html|argparse]] (optparse is marked as deprecated since the introduction of argparse with Python 2.7 and Python 3.2, use argparse unless you have to support older Python versions)
 * [[https://docs.python.org/2/library/getopt.html|getopt]] C-style command line parser
Line 5: Line 8:
The Python standard library has many modules that make creating commandline tools quite simple. Often command line tools are made with pure Python modules, or are a mixture of calls to an operating system and Python, through the subprocess module. Some of the commonly used modules to create commandline tools are: optparse, configparser, and subprocess. The [[https://docs.python.org/howto/argparse.html|Argparse Tutorial]] is an excellent read for getting you started with creating command line tools. See also OptionParsing.
Line 7: Line 10:
----

=== Other articles on Python command line tools ===

'''For sysadmins familiar with Bash scripting''': Beginner Level, circa 02/2008

 * [[http://magazine.redhat.com/2008/02/07/python-for-bash-scripters-a-well-kept-secret/ | Python for Bash scripters: A well-kept secret ]]

'''Using Python To Create Unix Commandline Tools:''' Beginning/Intermediate Level

 * Summary: An introductory article on how to create command line tools with Python. A beginner should learn how to create command line tool after finishing.

 * [[http://www.ibm.com/developerworks/aix/library/au-pythocli/?ca=dgr-lnxw82pythonunixtool&S_TACT=105AGX59&S_CMP=GR|Introduction To Creating CLI Tools with Python]]

'''Command line tool with optparse, subprocess, and logging''': Beginning/Intermediate level

 * Summary: This script provides shortcuts for using a Git repository but the script could be used as a template for other shell tools.

 * [[http://www.jperla.com/blog/2008/11/17/a-clean-python-shell-script/ | A Clean Python Shell Script ]].
Line 15: Line 37:

'''Using Python To Create Unix Commandline Tools:''' Beginning/Intermediate Level

 * Summary: An introductory article on how to create command line tools with Python. A beginner should learn how to create command line tool after finishing.

 * [[http://www.ibm.com/developerworks/aix/library/au-pythocli/?ca=dgr-lnxw82pythonunixtool&S_TACT=105AGX59&S_CMP=GR|Introduction To Creating CLI Tools with Python]]

'''Command line tool with optparse, subprocess, and logging''': Intermediate level

 * This script provides shortcuts for using a Git repository but the script could be used as a template for other shell tools: [[http://www.jperla.com/blog/2008/11/17/a-clean-python-shell-script/ | A Clean Python Shell Script ]].

Creating Command Line Tools With Python

Standard library support for parsing command lines

  • optparse and argparse (optparse is marked as deprecated since the introduction of argparse with Python 2.7 and Python 3.2, use argparse unless you have to support older Python versions)

  • getopt C-style command line parser

The Argparse Tutorial is an excellent read for getting you started with creating command line tools. See also OptionParsing.


For sysadmins familiar with Bash scripting: Beginner Level, circa 02/2008

Using Python To Create Unix Commandline Tools: Beginning/Intermediate Level

Command line tool with optparse, subprocess, and logging: Beginning/Intermediate level

  • Summary: This script provides shortcuts for using a Git repository but the script could be used as a template for other shell tools.
  • A Clean Python Shell Script.

PyCon2008 Presentation on Command Line Tools: Intermediate Level

CommandlineTools (last edited 2021-02-07 21:57:21 by IwanAucamp)

Unable to edit the page? See the FrontPage for instructions.