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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:05:22+00:00 2026-06-10T15:05:22+00:00

I am trying to work with argparse in python and I do not know

  • 0

I am trying to work with argparse in python and I do not know how to call the program at command line to see if it works.

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("DocID", type= int, help= "Insert DocID Here")
parser.add_argument("echo", help = "Enter in the FileName to be read")
args = parser.parse_args()
print args

This is my incredibly basic program that I am trying to use just to learn more about how argparse works. I just need to learn how and where to call the program to be able to use the arguments I give it.

Edit: To make my question more clear sorry. I have this code, but I do not know how to call the program as a whole so that I can run it. Like how would I run this in command line? Because when run just in IDLE it produces and error because of a lack of commands

  • 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-10T15:05:23+00:00Added an answer on June 10, 2026 at 3:05 pm

    an ArgumentParser’s parse_args method can take a list as input. That list is used for parsing the commandline arguments. So, a common idiom is:

    args = parser.parse_args('-a -b -c --value=True'.split())
    

    since str.split returns a list. ('a b c'.split() == ['a', 'b', 'c'])


    Usually when you add arguments, you do so like this:

    parser.add_argument('-a', '--a-long-name', type=int, ...)
    

    Arguments without a - or -- in front are positional arguments, so both of your arguments are positional. You can see a little of what is happening if you do:

    args = parser.parse_args(['1','foo'])
    print args.DocID # 1
    print args.echo  # foo
    

    which is the same as calling your script as python youscript.py 1 foo (without the list inside parse_args).

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

Sidebar

Related Questions

I am trying to write a parser class derived from the Python argparse ArgumentParser
I am trying to work out why I can not access the nested function
trying to work out how to use constructors with an inherited class. I know
I am trying to work through some questions and im not sure how to
trying to work out how to install zipArchive extension with MAMP, but not having
Im trying to work harder with those constructions but definitelly I dont see them
I am trying work out with MERGE statment to Insert / Update Dimension Table
Trying to work with Eclipse for Android (ADT plugin) development at my iMac (2.4Ghz,
Trying to work with groupby so that I can group together files that were
When trying to work with Qt's signal/slot mechanisms over more than one level of

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.