Python argparse Module: Difference between revisions

From GM-RKB
Jump to navigation Jump to search
m (Text replacement - ". * <B>Counter-Exam" to ". ** … * <B>Counter-Exam ")
m (Text replacement - "xam ple" to "xample")
 
Line 1: Line 1:
A [[Python argparse Module]] is a [[command-line argument processing]] [[programming function|Function]] for [[Python program]]s.
A [[Python argparse Module]] is a [[command-line argument processing]] [[programming function|Function]] for [[Python program]]s.
** …
** …
* <B>Counter-Exam
* <B>Counter-Example(s):</B>
ple(s):</B>
** [[Perl GetOptions Subroutine]].
** [[Perl GetOptions Subroutine]].
* <B>See:</B> [[Command-line Option]], [[Command-line Options Processor]].
* <B>See:</B> [[Command-line Option]], [[Command-line Options Processor]].

Latest revision as of 06:56, 7 January 2023

A Python argparse Module is a command-line argument processing Function for Python programs.



References

2017

import argparse 
parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer for the accumulator') parser.add_argument('--sum', dest='accumulate', action='store_const', const=sum, default=max, help='sum the integers (default: find the max)')
args = parser.parse_args() print(args.accumulate(args.integers))