#🔒 How to accept multiple parser arguments after 1 main argument?

8 messages · Page 1 of 1 (latest)

gilded bramble
#

I have set up a parser argument as such:

parser.add_argument('-r', '--run', metavar='plugin', nargs='+', action='store', help='Vælg hvilket plugin du gerne vil køre.')

I would like to be able to do this however:

py -m main -r 'klyngeindberetning' -i ['107', '108', '109']

Right now it can do:

py -m main -r 'klyngeindberetning' ['107', '108', '109']

but not the one above this ^, which I need because I have to distinguish between 2 types of IDs that you are supposed to ignore. One for "klynger" (could be e.g. -ik or -i -k) and one for documents/files (could be e.g. -i -d). How do I do that?

shadow raptorBOT
#

@gilded bramble

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gilded bramble
#

I could technically go with what it can do now:

py -m main -r 'klyngeindberetning' ['107', '108', '109']

and just check if any of the IDs match either a klynge or a document, but that's messy in my opinion. I would honestly rather be explicit.

#

Am I really forced to use subparsers?

gilded bramble
#

Fuck it, I'll just do

py -m main -r 'klyngeindberetning' 'klynge' 107 108 109
#

!close

shadow raptorBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.