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?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Debian/Ubuntu
Python v2.5/2.6 only.
Est. reading time N/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.


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 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 )

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum