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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:50:24+00:00 2026-06-14T18:50:24+00:00

I have a program that takes in arguments of the form filename:field[slice] , which

  • 0

I have a program that takes in arguments of the form filename:field[slice], which works fine. But I also wish to support the common notation that a filename of - means standard input. Sadly, -:field[slice] registers as an option with optparse (naturally), and hence does not show up as a positional argument. So I’m wondering if there is a way to get around this, for example by telling optparse that options starting with -: should be treated as positional arguments after all. The solution should preserve the ordering of the arguments, so foo:bar -:cow baz:dog should not become foo:bar baz:dog -:cow.

  • 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-14T18:50:26+00:00Added an answer on June 14, 2026 at 6:50 pm

    It seems to me that your best option is to preprocess sys.argv inserting a special token which you check for instead of -.

    args = [ '<stdin>:'+x[2:] if x.startswith('-:') else x for x in sys.argv[1:] ]
    opt_struct = parser.parse_args(args)
    

    In this case, you would parse <stdin> as standard input in your program instead of -.

    The transform gets a little more complicated if the : and the stuff after it are optional, but this is the gist of it anyway.

    9 times out of 10, these problems are likely impossible to solve with optparse, really tricky/messy to solve with argparse and trivial to solve by preprocessing sys.argv — But maybe that’s just my experience …

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

Sidebar

Related Questions

I have a perl program that takes input and output file arguments, and I'd
i have a program that needs command line arguments in the form : ./my_program
I have written a program that takes the filename from argv[1] and do operations
I have an existing java command-line program, that takes a bazillion of arguments and
I have created a Java program which takes some command line arguments to run.
I have a python program that takes the md5 & sha1 hash values of
I have been assigned wit the task to write a program that takes a
I have a program, that takes a long time to load. Because of this,
I have program that requires Python 3, but I develop Django and it uses
I have a program ( grabface ) that takes a picture of the face

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.