Questions tagged [argparse]
A Python module for implementing command-line interfaces
3,511
questions
0
votes
0
answers
20
views
How to choose from choices in Python cli
I am solving a project in JetBrains Academy. I cannot choose the choice from choices in cli configuration. I try to do the following code but i think it doesn't work, also there are no error messages. ...
0
votes
0
answers
24
views
how to change order of parent options shown in help screen?
I have the following Python 3 code:
main_parser = argparse.ArgumentParser(prog='my-prog')
common_optional_parser = argparse.ArgumentParser(add_help=False)
common_optional_parser.add_argument('--foo', ...
0
votes
0
answers
16
views
Python ArgumentParser strips with space and dash
I need to get the complete string inside quotes as an argument (Possible to use only argparse).But it will stop at space and dash and strips other words in quotes.
Please help to sole this.
Code :
...
1
vote
0
answers
29
views
argparse: How to use required positionals and subparsers together?
I'm encountering a simple use-case that argparse surprisingly doesn't seem to handle. I would like to have a required positional argument in addition to having multiple subparsers. The rationale is ...
0
votes
0
answers
25
views
Parse nested arguments using argparser python
I need to have an argument parsing logic that is able to parse below examples:
python3 some_script.py --build_config target=product1 step=x rom=y flavors=A B C
python3 some_script.py --build_config ...
-1
votes
0
answers
35
views
argparse: unrecognized arguments [duplicate]
I'm working on a Python todo terminal app where I'm implementing a method to deal with priority:
that should be used like so:
python3 todo.py 3 B
Assigning priority "B" to todo item number 3
...
0
votes
1
answer
37
views
Error in Python lib argparse method parse_args()
I am writing my Integration Tests code then I have a Parent BaseTestClass class to be extended to the children's classes. The Parent Base Class should read dynamic properties from the resource yaml ...
-1
votes
1
answer
22
views
how can i add new argparse commands in oop python depends on the if statement in the beginning of the class (libs: cmd, argparse)
I have been stuck with this problem for more than 4 days. I made a OOP Python program, which is supposed to be an CLI, so I made a logic of code like this. You use command python3 script.py first to ...
-1
votes
0
answers
23
views
passing a path with special characters from command line to python script
I have the following path: /fast6/share/POC/EmbeddedCam|DESKTOP-UT9UDPH
When I use Ipython:
In [1]: from glob import glob
In [2]: print(glob('/fast6/share/POC/EmbeddedCam|DESKTOP-UT9UDPH/**/*.bmp', ...
1
vote
1
answer
46
views
Distinguish default or command-line argument [duplicate]
Consider
import argparse
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--foo", type=str, default="bar", help="...
0
votes
1
answer
40
views
Dynamic argument parser for python
I am building a small wrapper which can accept a python command infer args and their associated values on the fly. I want something like and arg parser but the catch is that I do not know the ...
1
vote
0
answers
26
views
Typer - group \ inheritance arguments
I have several commands in the same typer app that get the same params or at least some of them (e.g. database connection arguments), but they are not sub-commands of each other.
I want to avoid copy-...
0
votes
1
answer
34
views
How to set argparse arguments after parser.add_argument
I have a python function that that bulid argparse parser automatically for other python programs and need to create a argument dynamically with parser.add_argument but in some niche use cases will ...
0
votes
1
answer
30
views
Calling a python argparse interface from python without Subprocess
Consider the following toy python application, which only have argparse CLI argparse interface.
import argparse
def main():
parser = argparse.ArgumentParser(description="Printer")
...
0
votes
1
answer
49
views
What is type=argparse.FileType('rb') in Python
I am looking at other person's Python code:
import argparse
parser = argparse.ArgumentParser(description="Recover files from an NTFS volume")
parser.add_argument('--mft', type=argparse....
0
votes
0
answers
17
views
How to add an "extended help" option to argparse
I have a program that calls a function with dozens of optional parameters, all of which can be customized via key-value pairs on the command line.
It every so often happens that I forget the exact ...
0
votes
0
answers
34
views
How to parse unknown args with sub parsers
I am trying to catch all unspecified args to my program. Typically I would do this using parser.parse_known_args(). However, this does not seem to work with subparsers.
Minimal example:
parser = ...
0
votes
0
answers
45
views
Python argparser help is not clear enough [duplicate]
I have made a python code, which needs some arguments to be passed:
parser = argparse.ArgumentParser(description='RAPIT', formatter_class=RawTextHelpFormatter)
parser.add_argument("-f", &...
0
votes
0
answers
33
views
"Following arguments are required" but I have already declared them (in Python machine learning project)
I am currently working on a project aimed to teach deaf people and their loved ones TSL(Turkish Sign Language). I am using machine learning to do so but I can't seem to train the programme with my ...
0
votes
2
answers
30
views
How to reconstruct (changed) sys.argv from argparse [duplicate]
I have an argparse that after parsing does preprocessing, changes and removes things etc.
Then it wraps a main that is used to get sys.argv.
Is there a preferred way to reconstruct a new sys.argv with ...
0
votes
1
answer
57
views
Python: how to print argparse in alphabetical order
I am looking for a canonical way to print the returned arguments of argparse in alphabetical order:
import argparse
parser = argparse.ArgumentParser('Some program', add_help=False)
parser.add_argument(...
0
votes
1
answer
52
views
How can I implement an argument parser with a variable number of positional arguments and optional subcommands in Python?
I am trying to implement an argument parser with the argparse module in Python.
My goal is to allow a variable number of positional input arguments to the main parser and then optionally call a sub ...
3
votes
1
answer
45
views
How to specify arguments in the form of `input=<INPUT>` in argparse
I could use argparse to add command line arguments in the form of
-i <INPUT> or
--input <INPUT>.
I want to instead have the command be in the form of input=<INPUT>.
Code
What I ...
0
votes
1
answer
61
views
How to parse command line arguments into an imported module via argparse
I have a python script that uses argparse to parse command line arguments, below is an example from it.
#main.py
import argparse
from my_folder.myscript import foo
#...lines of code
def main():
...
0
votes
0
answers
18
views
Python: Either measure bytes for x seconds or measure time for x amount of bytes
I need help. Im using argparsing and im trying to measure how much data that the system receives/sends either within a x amount of seconds or measure the time it takes to measure x bytes.
if I use -t (...
0
votes
1
answer
60
views
How do I pass arguments from tkinter function to external module?
I would like to call an external module (python script) from a tkinter button. My external module text_parser.py requires a single argument and looks like this:
import argparse
def main(filename):
...
1
vote
2
answers
255
views
SystemExit: 2 : error when calling parse_args()
I am getting the following error. As I am new to python I don't understand how to solve this error. Thank you in advance.
" usage: ipykernel_launcher.py [-h] -i INPUT [-f F]
ipykernel_launcher.py:...
0
votes
1
answer
67
views
Python argparse: can flag be optional for one argument?
I have a python script that uses argparse to look for more than 10 optional flags.
Is it possible to make the flag optional for one of the arguments? In my case it's the --time flag.
Normally I'd use ...
0
votes
0
answers
16
views
Is it possible to use the argument=value syntax to take a list of inputs in argparse using nargs="+"?
You can define an argument along the lines of:
parser.add_argument('--arg', nargs='+')
You can then parse arguments of the form --arg 1 2 3 and you'll get a list of ['1', '2', '3'] out.
You can parse ...
0
votes
1
answer
36
views
How to generate multiple lines of example command line when using python argparse
I have a python code called dd.py as follows.
import argparse
## Define the command line arguments
example_commands='''Example commands:\n
1. CAZyme annotation with isolated genome sequence as input ...
0
votes
0
answers
71
views
SystemExit: 2 : argpase parse_args() error on running pytest
I'm writing a constructor in a class DungeonGenerator to get the arguments' values from the command line via argparse. The environment for coding is VSCode and a simple Ubuntu terminal.
Here is the ...
1
vote
1
answer
63
views
How to convert a json file to parser by argparse? [duplicate]
I have a json file like,
{
"model_name_or_path": "microsoft/layoutlmv3-base",
"config_name": null,
"tokenizer_name": null,
"cache_dir":...
0
votes
2
answers
37
views
how do you directly call a python main function utilizing optparse?
folks, i inherited a python script main using optParse to construct a menu of items for the user to pick through:
def main():
parser = optParse(prog='script')
#parser.add_option("-e&...
0
votes
1
answer
36
views
Python argparse - optional argument 'overriding' required one
I'm looking for a way to have the following behavior with argparse.
Imagine as an example that I want a program that pretty print a file given as input.
And I also want an optional argument to display ...
0
votes
1
answer
35
views
Parse GET parameters
I have an REST API where the url looks like this:
class RRervice(pyrestful.rest.RestHandler):
@get('/Indicator/{rparms}')
def RR(self, rparms):
print(rparms)
...
0
votes
1
answer
41
views
How to allow macOS punctuations without using quotations or backslash in terminal but by using argparse or sys.argv? [duplicate]
Currently I have the following code:
bubble.py
import argparse
parser = argparse.ArgumentParser(description="Create pixel art bubble speech image")
parser.add_argument('text', type=str, ...
0
votes
1
answer
57
views
Python's argeparse using same option multiple times, but put those options in same list
In Python's argparse, using the same option multiple times puts those arguments in different lists. But I want those arguments on the same list.
The result I have got is:
# only the input portion
[
...
0
votes
0
answers
44
views
How to bypass argparse multi-word argument quotations?
I have a bubble.py script with an argparse set-up as below. There is only one positional argument 'text' and few other optional arguments (omitted for simplicity).
bubble.py
import argparse
parser = ...
-2
votes
1
answer
67
views
Using argparse to run associated functions [duplicate]
I use argparse to specify multiple command line arguments. How would I run a particular function that is associated with an argparse command line input?
Consider:
py test.py -s google.com
As the ...
0
votes
0
answers
109
views
Invoke an HFArgumentParser based script from within a Click command
I have a script trainmodel.py coming from an existing codebase (based on Hugginface ArgumentParsers) with almost 100 different arguments that is based on argparse. The script comes as a main() ...
0
votes
1
answer
49
views
What does the Ellipsis mean in this Python Function Documentation?
I've been researching for a couple of days what the ellipsis is supposed to mean in this context:
ArgumentParser.add_argument(name or flags...)
I understand that Ellipsis is a placeholder, or is used ...
0
votes
1
answer
41
views
Argparse: Passing multiple arguments via optional parameters when there is also a positional argument
When I have an argparse interface that only supports optional parameters, e.g.
parser.add_argument('-p', '--ports', nargs='+' type=int)
I can pass values to this parameter as follows
$ python3 ...
1
vote
0
answers
173
views
How to pass a list of arguments to Argo Workflows and accept it via argument parser
I am new to Argo Workflows. I am trying to pass a list of argument as parameter to Argo workflow. The workflow should take this list of argument via argument parser.But when i check the values inside ...
0
votes
1
answer
98
views
With argparse it it possible to process arguments only up to the last non-positional argument?
I'm writing a tool which passes arguments to another command provided with the arguments like this:
foo --arg1 -b -c bar -v --number=42
In this example foo is my tool and --arg1 -b -c should be the ...
1
vote
0
answers
26
views
How to escape leading dashes when passing a string argument to argparse? [duplicate]
I have a CLI Python application that I am attempting to add an optional command flag to to be handled via argparse. I'd like to be able to pass a value to a flag that starts with a dash - or ...
0
votes
1
answer
46
views
Mutually exclusive groups with required arguments if a specific group is chosen
I'm parsing a set of options for the Minesweeper game. There are two groups of option:
Predefined grid size (difficulty): --level easy|medium|hard
Custom grid size: --rows 16 --columns 24 --mines 40
...
0
votes
1
answer
40
views
How to import function from module that uses ArgParser without passing args
Let's say I have two modules:
a.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("arg", help="Some argument")
args = parser.parse_args()
def func():
...
2
votes
1
answer
110
views
Python argparse not working corrrectly with path in Windows
The argparse library in python doesn't work for the path, containing space, and '\' (backslash) at the end.
The parser in argparse parses the backslash at the end of path to " (double quotation).
...
0
votes
1
answer
3k
views
An exception has occurred, use %tb to see the full traceback. SystemExit: 2
can anyone tell me how to make this code works in jupyter or any notebook
Code
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help=&...
0
votes
0
answers
93
views
How do you add command line args to airflow python operator?
validation = PythonOperator(
task_id="validation",
python_callable=validation,
op_args=[
"--foo", foo,
"--bar", "null",
...