≡ Menu

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

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?

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.


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
Use 'apt-get autoremove' to remove them.
Suggested packages:
The following NEW packages will be installed:
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 ...


From the “Python Command Line Arguments Examples” page::

<pre lang="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 )
Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 0 comments… add one }
Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , ,