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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:40:13+00:00 2026-05-11T11:40:13+00:00

As mentioned in the docs the optparse.OptionParser uses an IndentedHelpFormatter to output the formatted

  • 0

As mentioned in the docs the optparse.OptionParser uses an IndentedHelpFormatter to output the formatted option help, for which which I found some API documentation.

I want to display a similarly formatted help text for the required, positional arguments in the usage text. Is there an adapter or a simple usage pattern that can be used for similar positional argument formatting?

Clarification

Preferably only using the stdlib. Optparse does great except for this one formatting nuance, which I feel like we should be able to fix without importing whole other packages. 🙂

  • 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. 2026-05-11T11:40:13+00:00Added an answer on May 11, 2026 at 11:40 am

    The best bet would be to write a patch to the optparse module. In the meantime, you can accomplish this with a slightly modified OptionParser class. This isn’t perfect, but it’ll get what you want done.

    #!/usr/bin/env python from optparse import OptionParser, Option, IndentedHelpFormatter  class PosOptionParser(OptionParser):     def format_help(self, formatter=None):         class Positional(object):             def __init__(self, args):                 self.option_groups = []                 self.option_list = args          positional = Positional(self.positional)         formatter = IndentedHelpFormatter()         formatter.store_option_strings(positional)         output = ['\n', formatter.format_heading('Positional Arguments')]         formatter.indent()         pos_help = [formatter.format_option(opt) for opt in self.positional]         pos_help = [line.replace('--','') for line in pos_help]         output += pos_help         return OptionParser.format_help(self, formatter) + ''.join(output)      def add_positional_argument(self, option):         try:             args = self.positional         except AttributeError:             args = []         args.append(option)         self.positional = args      def set_out(self, out):         self.out = out def main():     usage = 'usage: %prog [options] bar baz'     parser = PosOptionParser(usage)     parser.add_option('-f', '--foo', dest='foo',                       help='Enable foo')     parser.add_positional_argument(Option('--bar', action='store_true',                                    help='The bar positional argument'))     parser.add_positional_argument(Option('--baz', action='store_true',                                    help='The baz positional argument'))     (options, args) = parser.parse_args()     if len(args) != 2:         parser.error('incorrect number of arguments')     pass  if __name__ == '__main__':     main() 

    And the output you get from running this:

    Usage: test.py [options] bar baz    Options:     -h, --help         show this help message and exit     -f FOO, --foo=FOO  Enable foo  Positional Arguments:   bar  The bar positional argument   baz  The baz positional argument 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 108k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should include your test block in an "it" block.… May 11, 2026 at 9:14 pm
  • Editorial Team
    Editorial Team added an answer I don't think the question really makes much sense. There… May 11, 2026 at 9:14 pm
  • Editorial Team
    Editorial Team added an answer Use package called xvkbd. It should be within every linux… May 11, 2026 at 9:14 pm

Related Questions

This is one i struggled with for ages so thought I'd document somewhere. (Apologies
I read the part of the docs and saw that the ConfigParser returns a
(EDIT: This question is now outdated for my particular issue, as Google Code supports
Is there a documented max to the length of the string data you can

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.