Re: optparse question (python 2.6)

2013-09-02 Thread Andy Kannberg
Hi all, I tried with the example Peter gave me, and it works. But only when the options are boolean. At least, that is my conclusion with experimenting. I'll elaborate: The code to create 'mutually exclusive options': option_names = [ l, o , s ] toggled_options = [name for name in

Re: optparse question (python 2.6)

2013-09-02 Thread Peter Otten
Andy Kannberg wrote: I tried with the example Peter gave me, and it works. But only when the options are boolean. At least, that is my conclusion with experimenting. I'll elaborate: The code to create 'mutually exclusive options': option_names = [ l, o , s ] toggled_options = [name

optparse question (python 2.6)

2013-08-26 Thread Andy Kannberg
Hi python-guru's, I am new to Python, coming from a long history of Unix/linux shell programming. I am creating a Python script (In Python 2.6) which should be able to read command line options and arguments. So far, I figured out how to do that with optparse. I can add options (and arguments )

Re: optparse question (python 2.6)

2013-08-26 Thread Peter Otten
Andy Kannberg wrote: Hi python-guru's, I am new to Python, coming from a long history of Unix/linux shell programming. I am creating a Python script (In Python 2.6) which should be able to read command line options and arguments. So far, I figured out how to do that with optparse. I can

optparse question, passing unknown flags to subprocess

2009-05-20 Thread Joseph Garvin
I'm working on a python script that takes several command line flags, currently parsed by hand. I'd like to change the script to parse them with OptionParser from the optparse module. However, currently the script invokes a subprocess, and any flags the script doesn't understand it assumes are

Re: optparse question, passing unknown flags to subprocess

2009-05-20 Thread Robert Kern
On 2009-05-20 16:50, Joseph Garvin wrote: I'm working on a python script that takes several command line flags, currently parsed by hand. I'd like to change the script to parse them with OptionParser from the optparse module. However, currently the script invokes a subprocess, and any flags the

Re: optparse question

2009-01-28 Thread Thorsten Kampe
* Pat (Tue, 27 Jan 2009 14:04:28 -0500) I had no idea people were going to get so upset that I used a Windows example and go off on a tear. Nobody is upset, and nobody has gone off on a tear. The point about the Windows example is that the docs say in a close-to-screamingly- obvious

Re: optparse question

2009-01-27 Thread Thorsten Kampe
* Pat (Mon, 26 Jan 2009 20:02:59 -0500) Up until today, I never needed to pass any arguments to a Python program. [...] getopt resolved my immediate need, but I would like to know how one could use optparse to extract out the options from something like dir /s /b. If you actually read the

Re: optparse question

2009-01-27 Thread Pat
If you mean with / as the option designator instead of -: there doesn't appear to be a documented way of doing it. You would have to do some social engineering on the users to get them used to doing dir -s -b. In any case I thought the number of Windows users who know how to fire up a Command

Re: optparse question

2009-01-27 Thread Pat
Thorsten Kampe wrote: * Pat (Mon, 26 Jan 2009 20:02:59 -0500) Up until today, I never needed to pass any arguments to a Python program. [...] getopt resolved my immediate need, but I would like to know how one could use optparse to extract out the options from something like dir /s /b. If

Re: optparse question

2009-01-27 Thread John Machin
On Jan 28, 12:06 am, Pat p...@junk.net wrote: Thorsten Kampe wrote: * Pat (Mon, 26 Jan 2009 20:02:59 -0500) Up until today, I never needed to pass any arguments to a Python program. [...] getopt resolved my immediate need, but I would like to know how one could use optparse to extract

Re: optparse question

2009-01-27 Thread Thorsten Kampe
* John Machin (Tue, 27 Jan 2009 05:31:42 -0800 (PST)) Nobody is upset, and nobody has gone off on a tear. The point about the Windows example is that the docs say in a close-to-screamingly- obvious manner that /options are not supported, no matter what religion uses them. It was not, and still

Re: optparse question

2009-01-27 Thread Pat
I had no idea people were going to get so upset that I used a Windows example and go off on a tear. Nobody is upset, and nobody has gone off on a tear. The point about the Windows example is that the docs say in a close-to-screamingly- obvious manner that /options are not supported, no

Re: optparse question

2009-01-27 Thread Peter Otten
Pat wrote: The question was it possible to add a simple flag like 'd-' to optparse with no other parameters? Do you mean d- or -d? If the latter, what's wrong with Robert Kern's answer? Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: optparse question

2009-01-27 Thread Pat
Peter Otten wrote: Pat wrote: The question was it possible to add a simple flag like 'd-' to optparse with no other parameters? Do you mean d- or -d? If the latter, what's wrong with Robert Kern's answer? Peter I mean -d since that's what Unix commands expect for flags. My sole

Re: optparse question

2009-01-27 Thread Steve Holden
Peter Otten wrote: Pat wrote: The question was it possible to add a simple flag like 'd-' to optparse with no other parameters? Do you mean d- or -d? If the latter, what's wrong with Robert Kern's answer? I guess it got crowded out by the prima donnas anxious to help Pat phrase his/her

optparse question

2009-01-26 Thread Pat
Up until today, I never needed to pass any arguments to a Python program. I did all the requisite reading and found that I should use optparse instead of getopt. I read the documentation and since the words simple and easy often appeared in the examples and documentation, I just knew that

Re: optparse question

2009-01-26 Thread James Mills
On Tue, Jan 27, 2009 at 11:02 AM, Pat p...@junk.net wrote: (...) What does it take to pass single parameter to a program? http://docs.python.org/library/optparse.html stated that programs always have options. Is that so? What about dir /s? Sample code:

Re: optparse question

2009-01-26 Thread Robert Kern
On 2009-01-26 19:02, Pat wrote: Up until today, I never needed to pass any arguments to a Python program. I did all the requisite reading and found that I should use optparse instead of getopt. I read the documentation and since the words simple and easy often appeared in the examples and

Re: optparse question

2009-01-26 Thread Matimus
I did all the requisite reading and found that I should use optparse instead of getopt.   I read the documentation and since the words simple and easy often appeared in the examples and documentation, I just knew that it would be a snap to implement. I don't know where you got that. 'getopt'

Re: optparse question

2009-01-26 Thread John Machin
On Jan 27, 12:02 pm, Pat p...@junk.net wrote: Up until today, I never needed to pass any arguments to a Python program. I did all the requisite reading and found that I should use optparse instead of getopt.   I read the documentation and since the words simple and easy often appeared in the

An optparse question

2006-07-21 Thread T
I have a short program using optparse.OptionParser that prints out help message with -h flag: % myprog.py -h usage: myprog.py [options] input_file options: -h, --help show this help message and exit -v, --verboseprint program's version number and exit -o FILE

Re: An optparse question

2006-07-21 Thread fuzzylollipop
T wrote: I have a short program using optparse.OptionParser that prints out help message with -h flag: % myprog.py -h usage: myprog.py [options] input_file options: -h, --help show this help message and exit -v, --verboseprint program's version number and exit

Re: An optparse question

2006-07-21 Thread T
fuzzylollipop wrote: you can make the usage line anything you want. ... usage = 'This is a line before the usage line\nusage %prog [options] input_file' parser = OptionsParser(usage=usage) parser.print_help() ... No, that affects the string printed only *after* the usage = string.

Re: An optparse question

2006-07-21 Thread dan . gass
No, that affects the string printed only *after* the usage = string. What I would like to do is insert some string *before* the usage = string, which is right after the command I type at the command prompt. So I would like to make it look like this: The example was fine (except for a typo)

Re: An optparse question

2006-07-21 Thread Simon Forman
T wrote: fuzzylollipop wrote: you can make the usage line anything you want. ... usage = 'This is a line before the usage line\nusage %prog [options] input_file' parser = OptionsParser(usage=usage) parser.print_help() ... No, that affects the string printed only *after* the

Re: An optparse question

2006-07-21 Thread Simon Forman
[EMAIL PROTECTED] wrote: No, that affects the string printed only *after* the usage = string. What I would like to do is insert some string *before* the usage = string, which is right after the command I type at the command prompt. So I would like to make it look like this: The

Re: An optparse question

2006-07-21 Thread Steve Holden
T wrote: fuzzylollipop wrote: you can make the usage line anything you want. ... usage = 'This is a line before the usage line\nusage %prog [options] input_file' parser = OptionsParser(usage=usage) parser.print_help() ... No, that affects the string printed only *after* the usage =

Re: An optparse question

2006-07-21 Thread dan . gass
Nope. That only *nearly* does what T wants. The usage message will still be printed immediately *after* the 'usage: ' string. parser = OptionParser(usage=usage) parser.print_help() usage: THIS IS NEWLY INSERTED STRING usage: lopts.py [options] input_file

Re: An optparse question

2006-07-21 Thread John J. Lee
T [EMAIL PROTECTED] writes: [...] What I would like to do is insert some string *before* the usage = string, which is right after the command I type at the command prompt. So I would like to make it look like this: % myprog.py -h THIS IS NEWLY INSERTED STRING