-2

The final idea is to start my python program with a command like : python.exe -m myProgram execute --tags arg1 arg2 arg3 I'm trying to get "arg_1", "arg_2", ..., "arg_n" (with n unknown) inside a list and access all of them thanks to "tags"

I tried some ways like :

def run(self, **kwargs) -> None:
    tags = []
    for arg in kwargs.values():
        tags = tags.append(kwargs.get("tags", None))
    print(tags)

Or :

def run(self, **kwargs) -> None:
    tags = kwargs.get("tags", None)

But I can't get expected result. Should I change my command or does it exist a way to get tags like a list ? Please, any help ? Thank you

NickNick
  • 223
  • 1
  • 10
  • 2
    What are you using to get the input parameters? – Riccardo Bucco Aug 04 '20 at 14:52
  • You might want to look into this question https://stackoverflow.com/questions/15753701/how-can-i-pass-a-list-as-a-command-line-argument-with-argparse – Riccardo Bucco Aug 04 '20 at 14:55
  • 2
    Use the argument parser that comes with python [`argparse`](https://docs.python.org/3/library/argparse.html?highlight=argparse#module-argparse). In particular `nargs='*'`. Is there any reason to have `--tags` at all? Consuming all items in the argument list seems like `--tags` is unnecessary. – AChampion Aug 04 '20 at 14:56
  • Thank you guys, I'll read all of it. @AChampion, I may need to add other param with other names. ```--tags``` was an exemple. @Riccardo, thank you for the link. Looking for ```kwargs```, I didn' find/think to ```argparse```. – NickNick Aug 04 '20 at 15:46

1 Answers1

-1

Ok, I found how to do : python.exe -m myProgram execute --tags=[arg1,arg2,arg3] This format created the list I wanted to send to my program. Anyway, your links was interesting to read. Thanks again.

NickNick
  • 223
  • 1
  • 10