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 order in argparse

In python argparse i want to order the input by the user. For example in the following code i want the user to enter the -x. if the user enter any other, for example -b it should show an error. parser = argparse.ArgumentParser(description='SImple…
Aleesd
  • 41
  • 8
1
vote
1 answer

Need to input value for argparse. but it is not working

i am trying to use python argparse in the following code. I want the user to enter the text as below. -x 8 -l 9 -b 20 import argparse parser = argparse.ArgumentParser(description='Sample coding with arguments') parser.add_argument('-x', '--height',…
Aleesd
  • 41
  • 8
1
vote
1 answer

Partial parsing with argparse

I am currently writing a wrapper for git in python that allows to run certain git commands in multiple git repos. Now, I'd like to support all possible git commands, and I'd like to do it in the following way: I'd like argparse to only parse global…
daniel kullmann
  • 13,653
  • 8
  • 51
  • 67
1
vote
1 answer

FileNotFoundError: [WinError 2] The system cannot find the file specified but paths are correct

I check 20 other posts of people that keep getting this error, and none of em helped me solve my problem. I am trying to load a file into a TorchNeuralNet, to use for face verification. parser =…
Josip Juros
  • 349
  • 2
  • 12
1
vote
1 answer

'Namespace' object is not iterable

Attempting to pass an undetermined amount of integers using argparse. When I input: py main.py 3 2 %%writefile main.py import sorthelper import argparse integers = 0 #top-level parser creation parser = argparse.ArgumentParser("For sorting…
user1740117
  • 33
  • 1
  • 3
  • 7
1
vote
1 answer

While using Argparse "AttributeError: 'Namespace' object has no attribute 'command'" keeps showing up on terminal

After importing argparse (among others that I needed) I wrote the following piece of code: parser = argparse.ArgumentParser() (..some code with optional arguments...) requiredArguments = parser.add_argument_group("Required arguments") (..some code…
ccp2809
  • 13
  • 2
1
vote
2 answers

How to avoid printing the default values (argparse) in the help message (-h, --help)

Here is the code. def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description="infomedia" ) parser.add_argument("file", help="path to file") parser.add_argument( …
trueThari
  • 105
  • 1
  • 8
1
vote
2 answers

Python argparse: command lines values are not initialised for optional values

I have the following arguments which are to be parsed using argparse input_dir (string: Mandatory) output_dir (string: Mandatory) file_path (string: Mandatory) supported_file_extensions (comma separated string - Optional) ignore_tests (boolean -…
manoflogan
  • 31
  • 8
1
vote
0 answers

Run args = parser.parse_args(). Error: SystemExit: 2

When learning a piece of python code, some problems have occurred . code show as below: parser = argparse.ArgumentParser() parser.add_argument('--config_path', type=str, default="", help='the location of the data…
MoMoMo
  • 11
  • 1
  • 2
1
vote
2 answers

argparse python 3.6.11 on Redhat Linux, how to control program exit

I'm considering adding argparse to existing batch jobs which run python. These jobs take command line arguments which can vary depending on how the jobs are to run. I'd like to use the named argument feature in argparse but instead of exiting the…
Niall
  • 51
  • 1
  • 4
1
vote
1 answer

Argparse "arguments are required" error even when I have a default value set

I'm a little confused about the use of the default keyword argument for the add_argument() method in argparse. Here's a really simple script I ran to see how arguments are parsed: import argparse parser =…
strato
  • 47
  • 3
1
vote
1 answer

Argparse syntax for video processing

I am writing a python script to process a video using OpenCV package. I am quite new to python, so I am facing the following issue. In the end of the code I want to add the code below. However, I do not know how to add the input and the output file…
Alice
  • 11
  • 3
1
vote
1 answer

AttributeError: 'tuple' object has no attribute 'convert'

If I start my script I run in this weird error and I don*t know why or how to solve it. I really don't know why I hit this error. But it seems like there is something ain't right with argparse. Could someone please help me out with this…
user15309583
1
vote
1 answer

Getting UnicodeDecodeError

I getting this weird UnicodeDecodeError and I don't know why this error is caused but it would be really nice if someone could help me out with this issue:) Error message: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position…
user15309583
1
vote
1 answer

AttributeError: '_io.TextIOWrapper' object has no attribute 'rpartition'

I get this error: AttributeError: '_io.TextIOWrapper' object has no attribute 'rpartition' everytime I start my script. I don't know why I get this error could someone please help me out with this issue? My Code: import os import json import…
NoName
  • 51
  • 1
  • 9