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

  • SEARCH
  • Home
  • 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 8407713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:26:31+00:00 2026-06-09T23:26:31+00:00

I’m using argparse module in Python to parse parameters typed in a command line

  • 0

I’m using argparse module in Python to parse parameters typed in a command line interface. I have the following add_argument call to a subparser object:

submit_parser.add_argument('-pv','--provision',metavar='PROVISION', dest='PROVISION',
                                 help='provision system',
                                 action='store_true', default=False, required=False)

I get this error:

Traceback (most recent call last):
  File "./scripts/tp4", line 94, in <module> 
    main()
  File "./scripts/tp4", line 74, in main 
    modloader.loadModules(sub_parsers)
  File "/usr/lib/python2.6/site-packages/tp4/cli/Moduleloader.py", line 66, in loadModules 
    registered_modules[module_name].setSubparserArgs(module_sub_parser)
  File "/usr/lib/python2.6/site-packages/tp4/cli/modules/AutotestModule.py", line 135, in setSubparserArgs
    action='store_true', default=False, required=False)
  File "/usr/share/tp4/cli/zip/argparse.zip/argparse.py", line 1302, in add_argument
    TypeError: __init__() got an unexpected keyword argument 'metavar'

If I remove action or metavar parameters, it works. Why both can’t be together? There is nothing about this restriction in argparse documentation at http://docs.python.org/dev/library/argparse.html.

Thanks in advance for any help

  • 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-09T23:26:33+00:00Added an answer on June 9, 2026 at 11:26 pm

    A metavar only makes sense for positional arguments (think filenames at the end of the command line) or for when an argument takes arguments of its own (like --input-files foo.txt bar.txt).

    Your --provision argument is a flag because you set the action to store_true. It doesn’t take any arguments (i.e., nargs isn’t set). As such, it doesn’t make sense to have a metavar.

    From the argparse documentation:

    When ArgumentParser generates help messages, it need some way to refer to each expected argument. By default, ArgumentParser objects use the dest value as the “name” of each object. By default, for positional argument actions, the dest value is used directly, and for optional argument actions, the dest value is uppercased. So, a single positional argument with dest='bar' will be referred to as bar. A single optional argument --foo that should be followed by a single command-line argument will be referred to as FOO.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.