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 9313691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:56:43+00:00 2026-06-19T01:56:43+00:00

I’m writing a new CLI with pyton and using cmd and argparse libraries. When

  • 0

I’m writing a new CLI with pyton and using cmd and argparse libraries. When i set a argument and call it with a long text option it does not recognize it was a text and throws an exception.

Here is how i use arguments:

WACP:~ cli$ add -t group -n NameForNewGroup -desc 'Description for new group' -c 2

Response is:

unrecognized arguments: - t   g r o u p   - n   N a m e F o r N e w G r o u p   - d e s c   ' D e s c r i p t i o n   f o r   n e w   g r o u p '   - c   2

Here how i add arguments:

self.parser.add_argument('-t', '--type',
                                 dest='type',
                                 help=Language.MSG_ADD_TYPE_HELP,
                                 action='store',
                                 default='device'
)
self.parser.add_argument('-c', '--config',
                                 dest='config',
                                 help=Language.MSG_ADD_GROUP_HELP,
                                 action='store',
                                 default=0
)
self.parser.add_argument('-n', '--name',
                                 dest='name',
                                 help=Language.MSG_ADD_NAME_HELP,
                                 action='store',
                                 default='New Device'
)
self.parser.add_argument('-desc', '--description',
                                 dest='description',
                                 help=Language.MSG_ADD_DESC_HELP,
                                 type=complex,
                                 action='store',
                                 default='Default description for device or group included in configuration values')

I looked argparse documentation and did not configure how it could be.

I have to handle this long text parsing and make it work.

Is there anyone has an idea to solve that?

  • 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-19T01:56:44+00:00Added an answer on June 19, 2026 at 1:56 am

    Works for me. Maybe you can produce a minimal test case? What version of Python? Are you sure you’re using argparse and not optparse? Are you calling parse_args() on the right object? What’s the output of -h?

    import argparse
    p = argparse.ArgumentParser()
    p.add_argument('-t', '--type',
                   dest='type')
    p.add_argument('-c', '--config',
                   dest='config')
    p.add_argument('-n', '--name',
                   dest='name')
    p.add_argument('-desc', '--description',
                   dest='description')
    print(p.parse_args())
    

    When run:

    $ python test.py -t group -n NameForNewGroup -desc 'Description for new group' -c 2
    Namespace(config='2', description='Description for new group', name='NameForNewGroup', type='group')
    $ python test.py -h
    usage: test.py [-h] [-t TYPE] [-c CONFIG] [-n NAME] [-desc DESCRIPTION]
    
    optional arguments:
      -h, --help            show this help message and exit
      -t TYPE, --type TYPE
      -c CONFIG, --config CONFIG
      -n NAME, --name NAME
      -desc DESCRIPTION, --description DESCRIPTION
    

    Note

    1. Normally, if you have short (e.g. -t) and long (e.g. --type) arguments, the short arguments should be one character each. So -desc is a bit weird.

    2. You don’t want type=complex. The complex type is used for complex numbers, such as 1+0.5j.

    3. The default action is store, so you can omit it.

    • 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 trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.