optparse Questions
3
Using python optparse.py, is there a way to work out whether a specific option value was set from the command line or from the default value.
Ideally I would like to have a dict just like default...
6
Solved
Using python's optparse module I would like to add extra example lines below the regular usage output. My current help_print() output looks like this:
usage: check_dell.py [options]
options:
-h, ...
2
Solved
This is more like a code design question. what are good default values for optional options that are of type string/directory/fullname of files?
Let us say I have code like this:
import optparse
...
4
Solved
I'd like to be able to use ruby's OptionParser to parse sub-commands of the form
COMMAND [GLOBAL FLAGS] [SUB-COMMAND [SUB-COMMAND FLAGS]]
like:
git branch -a
gem list foo
I know I could switc...
Demoralize asked 28/4, 2010 at 20:28
6
Solved
I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that th...
Panelboard asked 4/8, 2009 at 18:32
3
Solved
I'm making a shell script with the optparse module, jut for fun, so I wanted to print a nice ascii drawing in place of the description.
Turns out that this code:
parser = optparse.OptionParser(
...
1
Solved
I currently script in Python but I wish to try Ruby for several reasons. I've looked at a lot of sample code and read a lot of documentation over the last week. One point of concern I have is the l...
Heidt asked 18/3, 2013 at 21:51
5
Solved
In python's OptionParser, how can I instruct it to ignore undefined options supplied to method parse_args?
e.g.
I've only defined option --foo for my OptionParser instance, but I call parse_args wi...
4
Solved
I'm trying to unit test some code that looks like this:
def main():
parser = optparse.OptionParser(description='This tool is cool', prog='cool-tool')
parser.add_option('--foo', action='store', h...
Dithyramb asked 8/1, 2009 at 23:37
2
Solved
I currently have a python file that utilizes sys.argv[1] to accept a string at the command line. It then performs operations on that string and then returns the modified string to the command line....
Presber asked 31/8, 2012 at 20:55
2
Solved
I've got a dozen programs that can accept input via stdin or an option, and I'd like to implement the same features in a similar way for the output.
The optparse code looks like this:
parser.add_...
3
Solved
According to PEP 257 the docstring of command line script should be its usage message.
The docstring of a script (a
stand-alone program) should be usable
as its "usage" message, printed when
...
1
With optparse, is there a simple way to define negative options, e.g., --no-cleanup?
I did it this way, but it's cumbersome and bug-prone, especially due to the None check which is easy to forget ...
3
Solved
I've started a serious attempt to learn some Python as my first programming language with some basic knowledge on algorithms. Since everyone recommends that the best way to start is to find somethi...
1
Solved
When I run this sample from the OptionParser documentation:
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.on("-v", "--[no-]verbose",...
1
Solved
I want to have params like this:
program dothis --additional --options
and:
program dothat --with_this_option=value
and I can't get how to do that. The only thing I managed to do is to use pa...
2
Solved
Take the following rather standard code:
from optparse import OptionParser
opts = OptionParser()
opts.add_option('-f', action="store_true")
opts.add_option("-x", dest="x", type="int", default=1)
...
6
Solved
I've been using optparse for a while now, and would like to add the ability to load the arguments from a config file.
So far the best I can think of is a wrapper batch script with the arguments h...
5
Solved
When using optparse i want to get the whole string after an option, but I only get part of it up to the first space.
e.g.:
python myprog.py --executable python someOtherProg.py
What I get in 'e...
5
Solved
Here is an example of how I would like to call my script:
python script.py -f file1.txt "string1" "string2" -f file2.txt "string3" "string4"
Every file that goes as input will have 2 strings ass...
Sharrisharron asked 21/3, 2011 at 0:36
2
Solved
My Python script (for todo lists) is started from the command line like this:
todo [options] <command> [command-options]
Some options can not be used together, for example
todo add --pos...
3
Solved
Is it possible to make an option in optparse a mandatory?
1
Solved
How can I take the opt result of
opt, args = parser.parse_args()
and place it in a dict? Python calls opt a "Values Instance" and I can't find any way to turn a Values Instance into a list or di...
Gratia asked 18/11, 2009 at 3:31
3
Solved
I'm writing a python script which I would like to be able to both call from the command line and import as a library function.
Ideally the command line options and the function should use the same ...
4
Solved
I'm writing a small program that's supposed to execute a command on a remote server (let's say a reasonably dumb wrapper around ssh [hostname] [command]).
I want to execute it as such:
./floep [c...
© 2022 - 2024 — McMap. All rights reserved.