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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:31:39+00:00 2026-05-30T08:31:39+00:00

Ok so If I have a parser like this example = argparse.ArgumentParser(description=’main parser’) example.add_argument(‘Kill’)

  • 0

Ok so If I have a parser like this

example = argparse.ArgumentParser(description='main parser')
example.add_argument('Kill')

subexample = example.add_subparsers()
person = subexample.add_parser('who')
person.add_argument('name')
person.add_argument('address')
animal = subexample.add_parser('what')
animal.add_argument('name')

args = parser.parse_args()

If I use args.name(), what is it going to give me? How can I specify which name I actually want? args.animal.name()? I am unsure, please help. And by the way I don’t support killing animals I just didn’t have many creative example I could think of.

  • 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-05-30T08:31:40+00:00Added an answer on May 30, 2026 at 8:31 am

    Use set_defaults:

    import argparse
    
    example = argparse.ArgumentParser(description='main parser')
    example.add_argument('Kill')
    
    subexample = example.add_subparsers()
    person = subexample.add_parser('who')
    person.add_argument('name')
    person.add_argument('address')
    person.set_defaults(kind = 'person')
    
    animal = subexample.add_parser('what')
    animal.add_argument('name')
    animal.set_defaults(kind = 'animal')
    args = example.parse_args()
    print(args)
    

    Running yields

    % test.py 1 who bar baz
    Namespace(Kill='1', address='baz', kind='person', name='bar')
    % test.py 1 what foo
    Namespace(Kill='1', kind='animal', name='foo')
    17:31:52 cyrano@farmer:~/test% 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do html parsing like this Android HTML Parser Example Now I have a
I'm new into PHO DOM Parser. I have a string like this : $coded_string
i have a xml file on a server that look for example like this
Consider example of the parser like this: object TestParser extends RegexParsers { override protected
I have a string like this that I need to parse into a 2D
Currently I just have a file like this that I manually parse into a
I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
I would like to implement a FSM/pushdown automaton parser for this syntax: parser with
I have a custom file format for graphs which looks like this: node1.link1 :
I have a data structure that represents C# code like this: class Namespace: string

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.