472,371 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

How to handle two-level option processing with optparse

optparse is way cool, far superior and cleaner than other options
processing libraries I've used.

In the next release of the Python debugger revision, I'd like to add
debugger options: --help and POSIX-shell style line trace (similar to
"set -x") being two of the obvious ones.

So I'm wondering how to arrange optparse to handle its options, but
not touch the script's options.

For example the invocation may be something like:
pdb --debugger-opt1 --debugger-opt2 ... debugged-script -opt1 opt2 ...

If a --help option is given to the script to be debugged, I want to
make sure it is not confused for the debugger's help option.

One simple rule for determining who gets whoit is that options that
come after the script name don't get touched in debugger's option
processing.

Another convention that has been used such as in the X11 "startx"
command is to use "--" to separate the two sets of options. However
this isn't as desirable as the simple rule mentioned above; it would
make entering "--" *all* the time when perhaps most of the time there
are no debugger options (as is the case now).

In other systems you can back an indication of the first option that
hasn't been processed and the remaining options are not touched.

It seems that with all of the flexibility of optparse it should handle
this. I'm not sure right now what the best way to do so would be
though. Suggestions?
Jan 26 '06 #1
7 1618
R. Bernstein wrote:
It seems that with all of the flexibility of optparse it should handle
this. I'm not sure right now what the best way to do so would be
though. Suggestions?

If you call OptionParser.disable_interspersed_args() on your parser, it will
stop parsing at the first positional argument, leaving other options unparsed.
--
Giovanni Bajo
Jan 26 '06 #2
Giovanni Bajo suggests:
If you call OptionParser.disable_interspersed_args() on your parser,
it will stop parsing at the first positional argument, leaving other
options unparsed.


Wow - that was a quick answer! Thanks - it works great!

I see how I missed this. Neither disable_.. or enable_.. have document
strings. And neither seem to described in the optparser section (6.21)
of the Python Library (http://docs.python.org/lib/module-optparse.html).

I wonder if something like this might be added to the Python Cookbook.

Thanks again.
Jan 26 '06 #3
R. Bernstein wrote:
Giovanni Bajo suggests:

If you call OptionParser.disable_interspersed_args() on your parser,
it will stop parsing at the first positional argument, leaving other
options unparsed.

Wow - that was a quick answer! Thanks - it works great!

I see how I missed this. Neither disable_.. or enable_.. have document
strings. And neither seem to described in the optparser section (6.21)
of the Python Library (http://docs.python.org/lib/module-optparse.html).

I wonder if something like this might be added to the Python Cookbook.

Well you are just as capable of adding it as anyone else, so knock
yourself out!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Jan 26 '06 #4
R. Bernstein wrote:
I see how I missed this. Neither disable_.. or enable_.. have document
strings. And neither seem to described in the optparser section (6.21)
of the Python Library (http://docs.python.org/lib/module-optparse.html).


http://docs.python.org/lib/optparse-other-methods.html
Jan 26 '06 #5
Steve Holden <st***@holdenweb.com> writes:
Well you are just as capable ...


Yes, I guess you are right. Done.

Couldn't find how to suggest an addition to the Python Cookbook (other
than some generic O'Reilly email), so I've put a submission to:
http://aspn.activestate.com/ASPN/Cookbook/Python/
Jan 26 '06 #6
Magnus Lycka informs:
[in response to my comment]:
I see how I missed this. Neither disable_.. or enable_.. have document
strings. And neither seem to described in the optparser section (6.21)
of the Python Library (http://docs.python.org/lib/module-optparse.html).


http://docs.python.org/lib/optparse-other-methods.html


Hmmm. A couple things are a little odd about this. First "Other
methods" seems to be a grab-bag category. A place to put something
when you don't know where-else to put it. The section called:
"Querying and manipulating your option parser" seems closer. Better I
think if the title were changed slightly to

Querying, manipulating, and changing the default behavior of your
option parse

Second, oddly I can't find this section "Other Methods" in the current
Python SVN source Doc/lib/liboptparse.tex. Best as I can tell, that
file does seem to be the section documenting optparse.
Jan 26 '06 #7
R. Bernstein wrote:
Magnus Lycka informs:
[in response to my comment]:
I see how I missed this. Neither disable_.. or enable_.. have document
strings. And neither seem to described in the optparser section (6.21)
of the Python Library (http://docs.python.org/lib/module-optparse.html).

http://docs.python.org/lib/optparse-other-methods.html


Hmmm. A couple things are a little odd about this. First "Other
methods" seems to be a grab-bag category. A place to put something
when you don't know where-else to put it. The section called:
"Querying and manipulating your option parser" seems closer. Better I
think if the title were changed slightly to

Querying, manipulating, and changing the default behavior of your
option parse

Second, oddly I can't find this section "Other Methods" in the current
Python SVN source Doc/lib/liboptparse.tex. Best as I can tell, that
file does seem to be the section documenting optparse.


Sounds like you should submit a documentation bug:
http://sourceforge.net/tracker/?grou...70&atid=105470
Plain text is fine -- just explain what needs to be changed.

Thanks!

STeVe
Jan 26 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body. Each...
2
by: Indiana Epilepsy and Child Neurology | last post by:
Before asking this questions I've spent literally _years_ reading (Meyer, Stroustrup, Holub), googling, asking more general design questions, and just plain thinking about it. I am truly unable to...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
12
by: Ken Brubaker | last post by:
I am using DB2 8.5 FP5 on Windows 2000 Server and have noticed what appears to be a handle leak. When I execute a DB2 connect statement in a command window, followed by a DB2 connect reset...
2
by: Alan Silver | last post by:
Hello, I am writing a page that allows the user to upload two images to the server. I have two HTMLInputFile controls on the page ... <input id="smallimage" Type="File" Runat="Server">...
13
by: Abhishek | last post by:
Hi, how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application only even if there is any other window in front of it. I dont...
2
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
9
by: =?Utf-8?B?UmFq?= | last post by:
How do I know which methods will throw exception when I am using FCL or other third party .Net library? I am developer of mostly native Windows applications and now .Net. After working few...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.