469,623 Members | 1,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

optparse: usage

I tried this:

Expand|Select|Wrap|Line Numbers
  1. usage = "Something, by Spacecoyote\nusage: %prog file [options]"
  2. parser = OptionParser(usage)
Expand|Select|Wrap|Line Numbers
  1. test.py --help
and I expected:
Expand|Select|Wrap|Line Numbers
  1. Something, by Spacecoyote
  2. usage: test.py file [options]
but I got:
Expand|Select|Wrap|Line Numbers
  1. usage: Something, by Spacecoyote
  2. usage: test.py file [options]
Is there an easy way to make optparse not force the usage prompt to start with usage? Or do I have to implement this myself.
Jan 19 '07 #1
1 1768
bvdet
2,851 Expert Mod 2GB
I don't know of a way to do it other than changing the source file.
Expand|Select|Wrap|Line Numbers
  1. def format_usage (self, usage):
  2.         return "%s" % usage
  3.  
  4. parser = OptionParser(usage='Something, by Spacecoyote\n%prog file [options]',
  5.                       prog='YourFile.py', version='x.x',
  6.                       description='This does not do anything'
  7.                       )
  8. opt, args = parser.parse_args()
  9.  
Output:
Expand|Select|Wrap|Line Numbers
  1. >>> Something, by Spacecoyote
  2. YourFile.py file [options]
  3. This does not do anything
  4. options:
  5.   --version   show program's version number and exit
  6.   -h, --help  show this help message and exit
Jan 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Gregory (Grisha) Trubetskoy | last post: by
8 posts views Thread by Hans-Joachim Widmaier | last post: by
7 posts views Thread by Henry Ludemann | last post: by
reply views Thread by Steven Bethard | last post: by
8 posts views Thread by T | last post: by
4 posts views Thread by rick | last post: by
4 posts views Thread by Count László de Almásy | last post: by
10 posts views Thread by James | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.