473,804 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_optio n(self):
self.add_option ("-h", "--help",
action="help",
help=_("show this help message and exit"))

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

def _populate_optio n_list(self, option_list, add_help=True):
if self.standard_o ption_list:
self.add_option s(self.standard _option_list)
if option_list:
self.add_option s(option_list)
if self.version:
self._add_versi on_option()
if add_help:
self._add_help_ option()

Jul 26 '06 #1
1 1779
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
4012
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. Please do not suggest default value solutions. Thanks.
9
2212
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 zero. I need to check if the user has passed the correct number of "option arguments". Something like:
3
2461
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", line 1, in ?
7
1717
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 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.
8
3521
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 individual swithces do not get passed to option parser.
9
3016
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 installation. Thanks, Peng
0
11477
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 (-15) / 266 closed (+13) / 523 total ( -2) New / Reopened Patches ______________________
0
1037
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). What I need is a command line util that can take various flags, these are 100% inclusive with no overlap. Easy, but now I want to also create some super-flags that setup a bunch of different values, and are exclusive to other super-flags. So for...
7
2156
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 works as CTRL-c-! whereas CTRL-c-! is missing, etc). How can I go back to the old python-mode or at least how do I get back the class browser? Michele Simionato
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.