Home>
I want to achieve
I want to get the nth array with an argument using argparse.
Only one character is output for the third argument.
"Nargs ='*'" is attached in argparse and it is output firmly as usual.
I don't want to add "nargs ='*'" to the third. What should I do?
import argparse
def TEST (test01, test02, test03):
a = test01 [0]
b = test02 [0]
c = test03 [0]
print (a)
print (b)
print (c)
def main ():
#Argument processing
parser = argparse.ArgumentParser (description ='service response')
parser.add_argument ('-a','--test01', nargs ='*', help ='set a')
parser.add_argument ('-b','--test02', nargs ='*', help ='set b')
parser.add_argument ('-c','--test03', help ='set c')
args = parser.parse_args ()
TEST (args.test01, args.test02, args.test03)
if __name__ == "__main__":
main ()
### Run ###
# python3 test.py -a hoge -b hogehoge -c hogehogehoge
# [Output result]
hoge
hogehoge
h
-
Answer # 1
Related articles
- python - handling of 1d array data when using the predict function in keras
- java - i want to know the rules of the argument list when using an array as the return type
- [python3] mix for statements with drawing using matplotlib
- python - i want to store a 3d array in an array using numpy
- i don't understand the exercises using python trigonometric functions
- python - typeerror when calculating the array of images called by imageopen ()
- introductory to o'reilly japan publishing in the text of python3 (3, 7 larger data structures), "lists, dictionaries, sets
- about batch change of file name using python
- java - description when using an array for the return value
- i want to manipulate the strings inside a python array
- python - how to sort a 3d array
- python - i want to store an object in an array
- how to use python 2d array
- python 3x - python3 tkinter toplevel behaves differently than intended
- python3 extract and delete duplicate data of date and time
- python - image recognition using cnn keras multiple inputs
- python - if you want to put a number directly in the argument of most_similar of gensim
- python 3x - how to rename a folder created using jupyternotebook
- about python argument and data definition
Trends
Correction points
Causenargs ='*'
If, the argument values will be a list. On the other hand, if not specified, it will be a single value instead of a list.Only the third
nargs ='*'
Is not specified, sopython3 test.py -a hoge -b hogehoge -c hogehogehoge
If, the content of the argument isHowever, when outputting
Therefore, only the first character of the character string "hogehogehoge" is output.