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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:55:33+00:00 2026-05-28T06:55:33+00:00

I want to use the pythons argparse module to parse my cli parameter string.

  • 0

I want to use the pythons argparse module to parse my cli parameter string. This works for the parameters a pass from terminal, but not with a given string.

import argparse

parser = argparse.ArgumentParser(description='Argparse Test script')
parser.add_argument("param", help='some parameter')

argString = 'someTestFile'
print(argString)

args = parser.parse_args(argString)

If I run this script I get this output:

~/someTestFile
usage: argparsetest.py [-h] param
argparsetest.py: error: unrecognized arguments: o m e T e s t F i l e

The ~/someTestFile is somehow transformed in o m e T e s t F i l e. As already mentioned, it works if I pass the filename from the terminal.

I could imagine, that this has something to do with string encodings. Does someone has an idea how to fix this?

  • 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-28T06:55:33+00:00Added an answer on May 28, 2026 at 6:55 am

    parser.parse_args() expects a sequence in the same form as sys.argv[1:]. If you treat a string like a sys.argv sequence, you get ['s', 'o', 'm', 'e', 'T', 'e', 's', 't', 'F', 'i', 'l', 'e']. ‘s’ becomes the relevant argument, and then the rest of the string is unparseable.

    Instead, you probably want to pass in parser.parse_args(['someTestFile'])

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

Sidebar

Related Questions

I think I want to use pythons built in calendar module to create an
I want to use this regular expression in Python: <(?:[^]*[']*|'[^']*'[']*|[^'>])+> (from RegEx match open
$whois abc.com I want to use python to hit this command, and then give
I want to use python-argparse with arguments and positional arguments. Say I have my
This is a follow up question from here . Where I want do go
I want to use python re module to filter the int number by the
I want to use a python module on my django website (matplotlib) that isn't
I want to use Python to access MFC document files generically? Can CArchive be
I want to use some Python libraries to replace MATLAB. How could I import
I use python -m SimpleHTTPServer when I want to run my web application locally,

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.