Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | Debian/Ubuntu Python v2.5/2.6 only. |
Time | N/A |
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 )
🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.
🐧 0 comments... add one ↓
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |