Questions tagged [argparse]

A Python module for implementing command-line interfaces

argparse is a module for implementing command-line interfaces.

From the module documentation:

The argparse module makes it easy to write user-friendly command-line interfaces. The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. The argparse module also automatically generates help and usage messages and issues errors when users give the program invalid arguments.

argparse was added to the stdlib in 2.7/3.2, deprecating .

Resources:

3535 questions
1
vote
1 answer

How to show me output of python argparse script, result of print exits command prompt

I'm still relatively new to Python. I'm supposed to write a Python script that prints out all files and directories under certain conditions: You can find the explanation of the exercise below. The solution to the exercise of my course…
Rainier
  • 11
  • 2
1
vote
1 answer

TypeError: coercing to Unicode: need string or buffer, _StoreAction found - python2.7

In my script I am trying to take in variables through the command line using argparse. The first variable is a direcotry name. The second is a string using in a split method later. I've set them both up as str type. Here is my input: $ python ppB.py…
1
vote
0 answers

Terminate option list after a certain option

CPython itself has certain command-line options that cause all further arguments to be interpreted as non-options ("terminates option list"). For example, -c cmd is such an option, so python3 -c 'import sys; print(sys.argv)' -E prints [-c, -E]; -E…
Kodiologist
  • 2,984
  • 18
  • 33
1
vote
2 answers

argparse - Modify the 'required' state of a subcommand's parent arguments

I'm trying to build a CLI in Python and I have an argument (--arg) that I want to reuse across multiple subcommands (req and opt). But one subcommand (req) will have to require --arg and the other (opt) doesn't. How do I resolve this without having…
what the
  • 398
  • 3
  • 10
1
vote
2 answers

Check what group was used in python argparse

I need to have two mutually exclusive groups of arguments in python using ArgumentParser. I use approach suggested by Jonathan here: subparsers = parser.add_subparsers(help = "You should explicitly specify either group_1 or gropup_2") parser_g1…
BaruchLi
  • 1,021
  • 2
  • 11
  • 18
1
vote
0 answers

Boto3 - Multi-file upload to specific S3 bucket "path" using CLI arguments

new coder here. For work, I receive a request to put certain files in an already established s3 bucket with a requested "path." For example: "Create a path of (bucket name)/1/2/3/ with folder3 containing (requested files)" I'm looking to create a…
1
vote
0 answers

Specify command line arguments for Python modules in distributed way (like abseil does)

How can I specify command line arguments on a per module base, that are then parsed when the application is run. This is basically how ABSEIL flags work, but I would prefer a more lightweight solution. Can this be achieved with argparse or any other…
jvh
  • 341
  • 3
  • 15
1
vote
1 answer

How to add required argument with optional flag

I'm writing a differ. The command line needs to handle two files - left and right. I would like the synapsis to be like this: differ.py [-f] FILE1 [[-t] FILE2] WHERE -f is the option that accepts FILE1, -t accepts FILE2. FILE1 is mandatory, FILE2…
Endrju
  • 2,354
  • 16
  • 23
1
vote
0 answers

argparse settings, set value after parsing

I am thinking about using argparse as my source of truth for command line settings and reduce a lot of code this way. For example, at the moment I am using separate variables to store the argparse arguments and also do some basic operations on…
Nico Müller
  • 1,784
  • 1
  • 17
  • 37
1
vote
1 answer

argparse parser: overriding options

I'm using pytest plugin - pytest-html The plugin has an option called '--self-contained-html'. I created my own plugin, that builds on this plugin, and adds another option. I want that, when someone uses my option, the original…
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
1
vote
1 answer

read tensor file via gcloud dataproc

hello how i should modify my code to read dataset2 properly ? %%writefile read_rdd.py def read_RDD(argv): parser = argparse.ArgumentParser() # get a parser object parser.add_argument('--test_set', metavar='test_set', type =ParallelMapDataset)…
1
vote
1 answer

Python argparser optional arg that requires other arguments

I have searched the internet and I couldn't find if it is possible to make an argument with python argparser package that is optional but when it is choosen it needs aeguments. For better understanding I will explain in code so you guys can…
1
vote
1 answer

creating command line influxDB string using argparse

I am reading data from influxdb into pandas with the below code:- import pandas as pd from influxdb import InfluxDBClient client = InfluxDBClient(host='10.0.0.0', port=7076, username='abcdefghi', password='dsdsd', ssl=False,…
1
vote
0 answers

send long parameter to python argparser

it's a part of my script: parser = ArgumentParser(description='extract state from bamboo build xml') parser.add_argument('-f', '--file', help='log file', required=True) parser.add_argument('-e', '--emails', help='emails list', required=True,…
1
vote
1 answer

Use Pythons argparse to make an argument being a flag or accepting a parameter

I am using argparse in Python 3. My requirement is to support the following 3 use-cases: $ python3 foo.py --test <== results e.g. in True $ python3 foo.py --test=foo <== results in foo $ python3 foo.py <== results in arg.test is…
Daniel Stephens
  • 2,371
  • 8
  • 34
  • 86
1 2 3
99
100