Linked Questions
32 questions linked to/from How can I pass a list as a command-line argument with argparse?
0
votes
1
answer
1k
views
Python passing a list of IPs:port via a command argument [duplicate]
I'm trying to parse a list of IP:ports via a command argument to variable called HOSTS, to be used in a function - read_head_block_ints.
parser = argparse.ArgumentParser(description='chain info ...
1
vote
1
answer
364
views
How to accept lists of multiple elements as command line arguments? [duplicate]
So I have a parser set up like such:
parser.add_argument('-f', '--foo', metavar='foo', type=ast.literal_eval, default=[], help="Foo")
And I need to let users enter multiple values if they so desire:
...
1
vote
3
answers
514
views
shell command run python script with args which is a list [duplicate]
i need to use shell command to run python script
but the args is a list
the python script:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
def main(task_list):
print('task_list:',...
0
votes
0
answers
439
views
Python Argparse and Bash [duplicate]
I have a script that uses argsparse to modify its inputs. For the example below, it runs a series of simulations, one after the other, based on the given arguments:
def main():
parser = argparse....
Alex's user avatar
- 1,038
-1
votes
2
answers
326
views
How to support List/Range of arguments in argparse? [duplicate]
In python I have:
parser = argparse.ArgumentParser(description='RANGES')
parser.add_argument('IP_Address', action='store', type=str)
How can I let the user provide a single IP adresses or range or ...
-1
votes
1
answer
61
views
How can i pass a "=" sign to cli parameter with argparse? [duplicate]
I want the argparse cli parameter to use "=" sign when i'm giving the list of the arguments with a space between them.
For example:
--repos= repo1 repo2 repo3
but when i'm giving the ...
0
votes
0
answers
42
views
How can I read a list using ArgParse in python? [duplicate]
What is incorrect in the following source code?
from argparse import ArgumentParser
class MainClass(object):
__input_files_vector = []
__output_directory = None
...
260
votes
11
answers
351k
views
Python csv string to array
Any simple library or function to parse a csv encoded string and turn it into an array or dictionary?
All the built in csv module examples take filepaths, not strings.
0
votes
1
answer
4k
views
Python argparse - using quotes
I want quotes around "arg1" "arg2" to be considered as separate arguments not in the same list and "arg1 arg2" as separate arguments but in the same list.
test.py taken from here
import argparse
...
0
votes
2
answers
1k
views
Pass an optional list to argparse
Is there a more elegant way to pass an optional list of integers to argparse than to pass a delimited string and parse it later? I also have a positional argument.
parser.add_argument('--ids', type=...
3
votes
1
answer
2k
views
Parse a nested list with python argparse
Assume that I am expecting a list of lists where the inner lists have different types and lengths, e. g.,
[[1, 2], ["foo", "bar"], [3.14, "baz", 20]]
how can I parse the above list using argparse?
...
0
votes
3
answers
2k
views
Passing list as an argument in python script in a subproces call
I am using Subprocess call to execute Insert_API from main script.Values to be inserted are stored in a list and I need to pass the list as an argument while subprocess call. It gives me error saying ...
0
votes
0
answers
2k
views
Pass an optional list of strings to a Pydantic-CLI - based argument parser
Based on the official pydantic-CLI docs I created the following CommandLineArguments-class from the base class "BaseModel":
from pydantic import BaseModel, Field, parse_obj_as
from typing ...
1
vote
1
answer
1k
views
Accepting more arguments with argparse
I am writing a script using python and argparse:
import argparse
parser = prgparse.ArgumentParser(description="do a or b")
parser.add_argument("-a", "--funcA", help=&...
1
vote
0
answers
2k
views
Pass list as argument to Python from Bash script
I would like to pass a list of strings as an argument to a Python script.
I have a bash script bash_script.sh like:
local dtype=float32
declare -a tokens
tokens=("CLS", "HI")
...