Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:59:56+00:00 2026-06-02T23:59:56+00:00

This code import argparse parser = argparse.ArgumentParser() parser.add_argument(‘target’, help=’Specifiy who to attack!’) magic =

  • 0

This code

import argparse

parser = argparse.ArgumentParser()

parser.add_argument('target', help='Specifiy who to attack!')

magic = ['fireball', 'heal', 'microwave']
parser.add_argument('-m', '--magic', nargs='*',
                    choices=magic,
                    help=('Magic'))
parsed_arguments = parser.parse_args()

Produces this help output

usage: Example.py [-h]
                  [-m [{fireball,heal,microwave} [{fireball,heal,microwave} ...]]]
                  target

positional arguments:
  target                Specifiy who to attack!

optional arguments:
  -h, --help            show this help message and exit
  -m [{fireball,heal,microwave} [{fireball,heal,microwave} ...]], --magic [{fireball,heal,microwave} [{fireball,heal,microwave} ...]]
                        Magic

I think the help output is confusing and makes it look like the target should be specified last, which however does not work: python example.py -m fireball troll gives argument -m/--magic: invalid choice: 'troll'.

I realize the grammar of the language becomes ambiguous, but it would still be possible to tell that as there should exist one word (target) last in the sentence troll is not an argument to the -m option.

Questions:

  1. Is there a way to let the positional argument be specified last without beating argparse to much?
  2. Is there a way to let the argparse help output indicate that target should indeed be specified first?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:59:58+00:00Added an answer on June 2, 2026 at 11:59 pm

    As previously mentioned in a comment, the standard methods on POSIX systems to denote the end of options is to separate the arguments and options by --.

    As for the second question: You might have to create your own HelpFormatter to achieve this, see formatter-class. You might be able to inherit from the default formatter and override only the necessary functions to generate the usage line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following code: import argparse parser = argparse.ArgumentParser(description='Adds a new modem
Please, help me. I dont know what is wrong with this code: import android.appwidget.AppWidgetProvider;
This is my code: from xgoogle.search import GoogleSearch, SearchError import urllib, urllib2, sys, argparse
have this code import threading def Thread(f): def decorator(*args,**kargs): print(args) thread = threading.Thread(target=f, args=args)
Consider this code: import socket store = [] scount = 0 while True: scount+=1
with this code: import wx import wx.aui class MyFrame(wx.Frame): def __init__(self, parent, id=-1, title='wx.aui
for this code: import sys import gevent from gevent import monkey monkey.patch_all() import requests
Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
When I run this code: import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.