Debian Linux Squeeze 6.0: Install Python v2.6/2.5 Argparse Module

by on March 19, 2013 · 0 comments· LAST UPDATED March 19, 2013

in , ,

I would like to use argparse module for Python 2.6 under Debian Linux. However, the code is not working. How do I install and use argparse Python module under Debian Linux 6.x for Python version 2.5 or 2.6?

Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsDebian/Ubuntu
Python v2.5/2.6 only.
Estimated completion timeN/A
The optparse-inspired command-line parsing library Argparse takes the best of the optparse command-line parsing module and brings it new life. Argparse adds positional as well as optional arguments, the ability to create parsers for sub-commands, more informative help and usage messages, and much more. At the same time, it retains the ease and flexibility of use that made optparse so popular. The following command must be run for Python version 2.5 or 2.6 only running on Ubuntu or Debian Linux v6.x.x.

Installation

Type the following command:
$ sudo apt-get install python-argparse
Sample outputs:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libavutil-extra-51 libggiwmh0-target-x libggi2 libgii1 libvo-aacenc0
  libgii1-target-x mplayer-skin-blue libggiwmh0 libggi-target-x
  libvo-amrwbenc0
Use 'apt-get autoremove' to remove them.
Suggested packages:
  python-argparse-doc
The following NEW packages will be installed:
  python-argparse
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 42.9 kB of archives.
After this operation, 307 kB of additional disk space will be used.
Get:1 http://mirror.anl.gov/debian/ squeeze/main python-argparse all 1.1-1 [42.9 kB]
Fetched 42.9 kB in 1s (25.9 kB/s)
Selecting previously deselected package python-argparse.
(Reading database ... 333589 files and directories currently installed.)
Unpacking python-argparse (from .../python-argparse_1.1-1_all.deb) ...
Setting up python-argparse (1.1-1) ...
Processing triggers for python-support ...

Example

From the "Python Command Line Arguments Examples" page::

 
<pre lang="python">
#!/usr/bin/python
import argparse
__author__ = 'nixCraft'
 
parser = argparse.ArgumentParser(description='This is a demo script by nixCraft.')
parser.add_argument('-i','--input', help='Input file name',required=True)
parser.add_argument('-o','--output',help='Output file name', required=True)
args = parser.parse_args()
 
## show values ##
print ("Input file: %s" % args.input )
print ("Output file: %s" % args.output )
 
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , , ,

Previous Faq:

Next Faq: