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_optio

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 option

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.

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, 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 s

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 mean

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-screa

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 ph

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 int

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
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 ma

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, an

Re: optparse question

2009-01-27 Thread John Machin
On Jan 28, 12:06 am, Pat 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 ext

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 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 Com

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 r

Re: optparse question

2009-01-26 Thread John Machin
On Jan 27, 12:02 pm, 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 examp

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. 'g

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 do

Re: optparse question

2009-01-26 Thread James Mills
On Tue, Jan 27, 2009 at 11:02 AM, Pat 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: #!/us

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 tha

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 *

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

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 *af

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: >

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 pri

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

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 = " s

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

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