optparse_lite 2.0
This is the lite version of 'optparse'.
About this script
* This script is the lite version of optparse.
How to use
* 1, Import script. import optparse_lite
* 2, Call parser class with usage and version code.
o In version 1.0(beta), You can set help file at parse argument.
o If you set help file, Please set file object to help file.
o if you write '%prog' in usage, this script convert it into file name.
parser=optparse_lite.OptionParse(usage="%prog [option]", version="1.0")
*
3, Add Option. And write option name, 'number of arg', 'desc' and 'func'.
o The 'number of arg' is number of arguments that you want.
number_of_arg=2 -> %prog -x test test -> ['test', 'test']
o The 'desc' is description of option.
o The 'func' is only function type. Please write function in advance.
def printout(list):
print list[0]
parser.add_option("-p","--print",number_of_arg=1,desc="printout",func=printout)
*
4, Call 'runparser' method. parser.runparser()
Exsample
import optparse_lite
def printstring(locallist):
print locallist[0]
def calc(locallist):
l = locallist
print int(l[0]) + int(l[1])
usage = "usage: %prog [option]"
version = "1.0.0"
parser = optparse_lite.OptionParse(usage, version)
parser.add_option(
"-p",
"--print",
number_of_arg=1,
desc="Print String.",
func=printstring
)
parser.add_option(
"-c",
"--calc",
"---calc-nums",
number_of_arg=2,
desc="Calcuation your num. ex):-c 2 3 -> 5",
func=calc
)
parser.runparser()
* 日本語で解説してほしい方は -> http://d.hatena.ne.jp/alicehimmel/20110322/1300803214
| File | Type | Py Version | Uploaded on | Size | # downloads |
|---|---|---|---|---|---|
| optparse_lite-2.0.tar.gz (md5) | Source | 2011-03-23 | 2KB | 315 | |
- Author: alice
- Home Page: http://d.hatena.ne.jp/alicehimmel/20110322/1300803214
- License: NYSL
- Package Index Owner: alice1017
- DOAP record: optparse_lite-2.0.xml
