472,958 Members | 2,330 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,958 software developers and data experts.

Worarrounding hardcoded Option class in optparse in Python 2.3

Hello,
I am doing some extreme use of optparse, that is, extending it as explained
on
http://docs.python.org/lib/optparse-...-optparse.html
I have subclassed OptionParser and Option. MyOptionParser uses MyOption as
option_class and in Python 2.4 it works. But I have to target Python 2.3.
In Python 2.3 the help and version options seem to be created before even a
parser is created and they are created using a hardcoded call to Option.
So, they are not using MyOption. I am creating MyOption specifically for
the help and version Option so I need the to be MyOption.
I check out the documentation of this module for Python 2.3 and it
recommends the same procedure:
http://www.python.org/doc/2.3/lib/op...r-reasons.html
Is this a bug in Python 2.3 that was solved in 2.4 and nobody cared to
backport ?
At any rate, what are my options (no pun intended) ?
I could copy and paste the fix[1] from Python 2.4 into MyOptionParser; I
checked it carefull and it seems it would work, but I am not sure, does
anybody know ?
Should I override the hardcoded module variables of optparse in 2.3 ? (that
seems like a bad, bad idea).
I am open to suggestions.
Thanks.
--
Pupeno <pu****@pupeno.com(http://pupeno.com)

[1] That would be:

def _add_help_option(self):
self.add_option("-h", "--help",
action="help",
help=_("show this help message and exit"))

def _add_version_option(self):
self.add_option("--version",
action="version",
help=_("show program's version number and exit"))

def _populate_option_list(self, option_list, add_help=True):
if self.standard_option_list:
self.add_options(self.standard_option_list)
if option_list:
self.add_options(option_list)
if self.version:
self._add_version_option()
if add_help:
self._add_help_option()

Jul 26 '06 #1
1 1721
For the record, the copy and paste fix seems to have worked, so far.

Pupeno wrote:
Hello,
I am doing some extreme use of optparse, that is, extending it as
explained on
http://docs.python.org/lib/optparse-...-optparse.html
I have subclassed OptionParser and Option. MyOptionParser uses MyOption as
option_class and in Python 2.4 it works. But I have to target Python 2.3.
In Python 2.3 the help and version options seem to be created before even
a parser is created and they are created using a hardcoded call to Option.
So, they are not using MyOption. I am creating MyOption specifically for
the help and version Option so I need the to be MyOption.
I check out the documentation of this module for Python 2.3 and it
recommends the same procedure:
http://www.python.org/doc/2.3/lib/op...r-reasons.html
Is this a bug in Python 2.3 that was solved in 2.4 and nobody cared to
backport ?
At any rate, what are my options (no pun intended) ?
I could copy and paste the fix[1] from Python 2.4 into MyOptionParser; I
checked it carefull and it seems it would work, but I am not sure, does
anybody know ?
Should I override the hardcoded module variables of optparse in 2.3 ?
(that seems like a bad, bad idea).
I am open to suggestions.
Thanks.
--
Pupeno <pu****@pupeno.com(http://pupeno.com)
Jul 27 '06 #2

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

Similar topics

4
by: Sam Smith | last post by:
I am using optparse for the commandline parsing for my programs. I was wondering if it is possible to detect if an option or option-arg has been specified on the commandline by the user or not....
9
by: Ritesh Raj Sarraf | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'm using optparse module to parse all options and arguments. My program uses mostly "option arguments" hence my len(args) value is always...
3
by: Karlo Lozovina | last post by:
If I create a file with only one line: --- from optparse import OptionParser --- I get this when I try to run it from "DOS" prompt: Traceback (most recent call last): File "optparse.py",...
7
by: R. Bernstein | last post by:
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...
8
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
9
by: PengYu.UT | last post by:
Hi, I feel argparse has some useful things that optparse doesn't have. But I can't find it argparse in python library reference. I'm wondering when it will be available in the python standard...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 342 open (-38) / 3712 closed (+54) / 4054 total (+16) Bugs : 951 open (-14) / 6588 closed (+33) / 7539 total (+19) RFE : 257 open...
0
by: Benny the Guard | last post by:
I have become familiar with optparse code to parse various options into a program. But right now having some difficulties with a new project I am working on (not a class project, just a new script)....
7
by: Michele Simionato | last post by:
I have noticed that the python-mode for Emacs that comes with the latest Ubuntu is missing the class browser. Moreover if works differently from the python-mode I was used to (for instance CTRL-c-c...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.