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  b = test02  c = test03  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
--c = test03  + c = test03
nargs ='*'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, so
python3 test.py -a hoge -b hogehoge -c hogehogehogeIf, the content of the argument is
args.test01 = ["hoge"] args.test02 = ["hogehoge"] args.test03 = "hogehogehoge"
However, when outputting
Therefore, only the first character of the character string "hogehogehoge" is output.
- 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
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file