optional args for getopt()

bvdpoel at uniserve.com bvdpoel at uniserve.com
Fri Aug 24 12:17:43 EDT 2001


Richard Jones wrote:
> 
> On Friday 24 August 2001 09:48, bvdpoel at uniserve.com wrote:
> > Richard Jones wrote:
> > > On Thursday 23 August 2001 12:59, bvdpoel at uniserve.com wrote:
> > > > Is there a way to signal that the arg for getopt in optional. In C I
> > > > can set an option string to something like:
> > >
> > > Sorry, to answer this question directly - I don't believe it's possible
> > > in the current getopt code. Your best bet would possibly be to locally
> > > change getopt to do qhat you need (and at the same time, generate a patch
> > > that can be submitted to python.sf.net).
> > >
> > >    Richard
> >
> > Thanks. I really was hoping NOT to have to reinvent the wheel. For now
> > I'll just leave well enough alone and do my own parsing.... but if any
> > maintainers are reading this, it would be nice to have GNU compatibility
> > in this.
> 
> I wasn't talking about re-inventing the wheel... I was talking about a minor
> change to an existing one. OK, attached is a simple patch against the getopt
> module from the 2.1 distribution (encoded so mail systems don't mess with the
> formatting). I've submitted this to the sourceforge patch repository.
> 
> BTW: in a large number of cases in the python library - we, the python
> community, are the "maintainers" of the code. Modules get extended when
> someone has a need and submits the code the python maintainers.
> 
> Note: I've only implemented this behaviour - none of the other GNU
> extensions. Hope it's useful for you.

Thanks.

I'm wondering if there isn't a better way to go on all this...

 - Since what I (and I'm guessing others) is looking for is GNU
compatibility, and since this stuff has already been written in C why
not just write a C extension which calls the C library function. I've
never written a C python extension, but it might be an interesting
learning experience. It is on my list.

 - But, thinking a bit more, it appears that python already calls the
relevant function. So, should getopt() be added as part of python
itself? Hmmm, probably a bunch of reasons for this not to happen?


-- 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at uniserve.com
WWW:   http://users.uniserve.com/~bvdpoel





More information about the Python-list mailing list