Skip to main content

Questions tagged [argparse]

A Python module for implementing command-line interfaces

argparse
-2 votes
2 answers
80 views

Python argparse parse_known_args(namespace=); use of namespace?

Trying to understand pymol-open-source setup.py, I came accross this use of argparse.parse_know_args() namespace keyword: import argparse ... class options: osx_frameworks = True jobs = int(...
pippo1980's user avatar
  • 2,731
-1 votes
0 answers
30 views

Running a script from another script with argparse parameters

I have been given a Python application and I need to make it into an Azure Function and within its main function we have this argparse configuration: if __name__ == "__main__": parser = ...
Jason_Hough's user avatar
1 vote
1 answer
52 views

How to make argparse work nicely with enums and default values?

I have an enum: from enum import auto, Enum class MyEnum(Enum): ONE = auto() TWO = auto() THREE = auto() and I want to use it as an argument with argparse. To be more specific, I want to ...
Shai Avr's user avatar
  • 1,220
0 votes
1 answer
28 views

Get parent parser from argparse's parser

I have certain python code which takes CLI arguments and handles them using argparse's parser. I have a parent parser as such: verbose_quiet_parent_parser = argparse.ArgumentParser(add_help=False) ...
Suhas Srivastava's user avatar
1 vote
2 answers
46 views

How can I add a keyword argument with a default value when setting up argparse in Python?

I have a function that sets what arguments can be passed to a command line when calling on a function, using argparse: def parse_arguments(args): parser = argparse.ArgumentParser(usage=...
user21641220's user avatar
0 votes
1 answer
65 views

parser add_mutually_exclusive_group - how can I set a default value?

We use Python and Django for our websites. We set a test command that adds to the default Django test command: from django.core.management.commands import test class Command(test.Command): def ...
Uri's user avatar
  • 3,139
-3 votes
2 answers
75 views

How to incorporate argparse into a python function with two arguments

I am trying to figure out how to incorporate argparse into a python function I have created that accepts two arguments, so that it is executable in the command line. For example in this function below:...
NicoMane's user avatar
1 vote
1 answer
33 views

How to Resolve ArgumentParser Conflict with -h/--help in Subcommands?

I'm developing a Python command-line tool using argparse with multiple modules, each having its own set of arguments. I'm using separate classes to define each module's arguments and integrate them ...
Mahdi Baghbanzadeh's user avatar
0 votes
2 answers
30 views

How to get arguments from ArgParser to write to a textfile so it can be read with `fromfile_prefix_chars`

I want a script to save all arguments (whether provided or populate from defaults or read from a text file) to a text file in such a format that I can re-run the script using fromfile_prefix_chars ...
Edgar H's user avatar
  • 1,470
0 votes
0 answers
28 views

Key-value “Sub-paramettre” with Python’s argparse

I want to make the --new-entry paramettre be able to process a key-value sequence with space as statement separator. As example: script.py --new-entry name="The Republic" author="Plato&...
fauve's user avatar
  • 256
-1 votes
1 answer
58 views

How to get " sign for string args in python argparse

I want to write a program in Python that gets args of unspecified number and type. I can do this with argparse as follows: parser = argparse.ArgumentParser() parser.add_argument('args', help='Help', ...
ArianNa's user avatar
  • 31
1 vote
1 answer
65 views

A Python argparse curiosity

Given the following code: # parseargs.py import argparse parser = argparse.ArgumentParser() parser.add_argument("s") args = parser.parse_args() When I run this, it all works as expected ...
David Shaw's user avatar
0 votes
3 answers
56 views

have top-level parser and subparsers act on the same variable

i have an ArgumentParser with sub-parsers. Some flags are common for all sub-parsers, and I would like to be able to specify them either before or after the sub-command, or even mix before and after (...
umläute's user avatar
  • 30.6k
0 votes
0 answers
26 views

Creating optional argparse arguments, and ones that takes either None or a str as input

I'm writing argparse arguments for a command line function where: More than one of the functions are optional, and One of the functions defaults to None if no file path string is provided The code ...
TheEponymousProgrammer's user avatar
0 votes
1 answer
43 views

Strange shell tab completion behaviour

I'm using the argparse Python module in a script that looks like this: import argparse def get_info(line: str) -> tuple: print(line.split("|")) def main(): p = argparse....
BrewsLee's user avatar

15 30 50 per page
1
2 3 4 5
242