3,639 questions
-1
votes
0
answers
42
views
Unrecognized arguments on Python with PyInstaller and argparse
I work on a script Python and I try to send args and use PyInstaller at same time.
This is an example:
#!/usr/bin/env python3
import argparse
import sys
print(sys.argv)
parser = argparse....
1
vote
1
answer
83
views
Why argparse treats unknown arg as a known arg in case unknown arg name is part of a known arg name? [duplicate]
I have a Python project that uses argparse. I noticed an unwanted behavior of argparse when parsing some unknown arguments.
I use both known and unknown arguments. I have a parameter --list-installed. ...
2
votes
1
answer
78
views
How do I change argparse positional argument destination name?
I am having trouble using add_argument's dest parameter with positional arguments. The reason I want this is that I use nargs='*' and it makes sense to me to have the argument name be singular so that ...
0
votes
2
answers
99
views
Exclusive group of arguments with optional values
The following code
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--foo', nargs='?')
parsed_args = parser.parse_args()
creates an optional argument with an ...
0
votes
1
answer
52
views
Check if Python argparse used explicit CLI argument or default value?
I derive some settings from my parser that I latter store on disk to be reloaded again, during the reload I want to overwrite some values but keep the first ones, similar to new default values.
I want ...
0
votes
1
answer
98
views
How to correctly add a custom argument to a Django Extensions 'Management Job' command?
I have a custom Django management job created using django_extensions that deletes old database records. To avoid unintended deletions, I want to add a --dry-run argument to simulate deletions without ...
1
vote
2
answers
84
views
Running Uvicorn on Mac command line results in error uvicorn: error: unrecognized arguments [closed]
When I run my FastAPI app with the Uvicorn command, the command line args are not recognized:
(env) mydir$ uvicorn main:app --port 8000 --host 0.0.0.0 --reload
...
uvicorn: error: unrecognized ...
0
votes
1
answer
53
views
Python argparse: 'usage' text showing formatter object when using custom formatter
I got a script with a list of arguments defined with argparse. Because I want to have bullet points and line breaks in the help text, I added a custom formatter. That works like a charm but the ...
0
votes
0
answers
56
views
Why unrecognized Argparse arg1 in bare "my_script .py arg1" vs "python my_script.py arg1"
I can run a script on the command line with an argument either as the bare "script.py arg1" or I can run it as "python script.py arg1". Both work until I use argparse for command ...
1
vote
0
answers
41
views
How to pass in different script parameters to a Run Config when using Debug in PyCharm
I'm writing a Flask app and I would like to automatically pass debug into app.run() when clicking the Pycharm 'Debug' button (instead of Run).
I have argparse setup so that if --debug gets passed in ...
1
vote
3
answers
139
views
Create a common CLI entry point in Python
First of all, I cannot share the original code so I apologize in advance if the example used does not make sense.
I also know the code I present has some issues and will not run as it is, but it is ...
0
votes
2
answers
98
views
Dynamic argument types in Python + argparse
I want to create a CLI using Python and argparse. The CLI should have options to specify a list of values, and also to dynamically specify the type of the values (str, int, float, etc.) in that list (...
1
vote
1
answer
105
views
How to make argparse accept either subcommands or a direct argument?
I have a CLI tool for managing Docker containers. Here's my current parser setup:
def create_parser():
parser = argparse.ArgumentParser(description="Docker container manager")
...
1
vote
2
answers
209
views
How do I ignore case of double-dash options (long-options) in argparse?
I've written some command-line tools that have certain options having both single-dash-one-letter-abbreviations (short-options), as well as more verbosely named double-dash options (long-options) - as ...
0
votes
1
answer
81
views
Handle an option only if another option is used
I need to process command-line options from my Python script that correspond to the syntax
tesy.py [-h] [-a [-b]]
(This is just a simplistic example illustrating the problem; in reality my script has ...