467,861 Members | 1,581 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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
  • viewed: 1533
Share:
1 Reply
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Ritesh Raj Sarraf | last post: by
3 posts views Thread by Karlo Lozovina | last post: by
7 posts views Thread by R. Bernstein | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
7 posts views Thread by Michele Simionato | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.