473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1742
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.