- 浏览: 300797 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (98)
- philosophy (0)
- python (21)
- mac (6)
- linux (12)
- vfx (8)
- web2.0 (2)
- win (2)
- java (2)
- it (1)
- ruby (1)
- gtd (6)
- digest (1)
- maya (1)
- sns (1)
- dip (2)
- ldap (1)
- eclipse (1)
- mba (1)
- lisp (2)
- haskell (3)
- life (4)
- c# (1)
- c++ (3)
- sci-fi (1)
- news (2)
- poem (2)
- reading (2)
- mysql (1)
- coffee (0)
- houdini (1)
- economics (1)
- emacs (1)
- render (1)
- expect (0)
- shake (1)
最新评论
-
aib628:
真是好东东,正在学习中!
Jython 简单入门 -
jiguanghover:
不错的例子,好好看看
Jython 简单入门 -
rmn190:
不错, 现在正在从Java转到Python这边来, 以前用Ja ...
Jython 简单入门 -
kandari:
有没有openSUSE的
用NTP网络时间协议同步你的IT系统 -
CharlesCui:
winmail.dat是个垃圾!气死我了.
如何提取 winmail.dat ?
getopt -- Parser for command line options
This module helps scripts to parse the command line arguments in sys.argv. It supports the same conventions as the Unix getopt() function (including the special meanings of arguments of the form `-' and `--'). Long options similar to those supported by GNU software may be used as well via an optional third argument. This module provides a single function and an exception:
getopt( args, options[, long_options])
Parses command line options and parameter list. args is the argument list to be parsed, without the leading reference to the running program. Typically, this means "sys.argv[1:]". options is the string of option letters that the script wants to recognize, with options that require an argument followed by a colon (":"; i.e., the same format that Unix getopt() uses).
Note: Unlike GNU getopt(), after a non-option argument, all further arguments are considered also non-options. This is similar to the way non-GNU Unix systems work.
long_options, if specified, must be a list of strings with the names of the long options which should be supported. The leading '--' characters should not be included in the option name. Long options which require an argument should be followed by an equal sign ("="). To accept only long options, options should be an empty string. Long options on the command line can be recognized so long as they provide a prefix of the option name that matches exactly one of the accepted options. For example, if long_options is ['foo', 'frob'], the option --fo will match as --foo, but --f will not match uniquely, so GetoptError will be raised.
The return value consists of two elements: the first is a list of (option, value) pairs; the second is the list of program arguments left after the option list was stripped (this is a trailing slice of args). Each option-and-value pair returned has the option as its first element, prefixed with a hyphen for short options (e.g., '-x') or two hyphens for long options (e.g., '--long-option'), and the option argument as its second element, or an empty string if the option has no argument. The options occur in the list in the same order in which they were found, thus allowing multiple occurrences. Long and short options may be mixed.
gnu_getopt( args, options[, long_options])
This function works like getopt(), except that GNU style scanning mode is used by default. This means that option and non-option arguments may be intermixed. The getopt() function stops processing options as soon as a non-option argument is encountered.
If the first character of the option string is `+', or if the environment variable POSIXLY_CORRECT is set, then option processing stops as soon as a non-option argument is encountered.
New in version 2.3.
exception GetoptError
This is raised when an unrecognized option is found in the argument list or when an option requiring an argument is given none. The argument to the exception is a string indicating the cause of the error. For long options, an argument given to an option which does not require one will also cause this exception to be raised. The attributes msg and opt give the error message and related option; if there is no specific option to which the exception relates, opt is an empty string.
Changed in version 1.6: Introduced GetoptError as a synonym for error.
exception error
Alias for GetoptError; for backward compatibility.
An example using only Unix style options:
>>> import getopt
>>> args = '-a -b -cfoo -d bar a1 a2'.split()
>>> args
['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2']
>>> optlist, args = getopt.getopt(args, 'abc:d:')
>>> optlist
[('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')]
>>> args
['a1', 'a2']
Using long option names is equally easy:
>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
>>> args = s.split()
>>> args
['--condition=foo', '--testing', '--output-file', 'abc.def', '-x', 'a1', 'a2']
>>> optlist, args = getopt.getopt(args, 'x', [
... 'condition=', 'output-file=', 'testing'])
>>> optlist
[('--condition', 'foo'), ('--testing', ''), ('--output-file', 'abc.def'), ('-x',
'')]
>>> args
['a1', 'a2']
In a script, typical usage is something like this:
This module helps scripts to parse the command line arguments in sys.argv. It supports the same conventions as the Unix getopt() function (including the special meanings of arguments of the form `-' and `--'). Long options similar to those supported by GNU software may be used as well via an optional third argument. This module provides a single function and an exception:
getopt( args, options[, long_options])
Parses command line options and parameter list. args is the argument list to be parsed, without the leading reference to the running program. Typically, this means "sys.argv[1:]". options is the string of option letters that the script wants to recognize, with options that require an argument followed by a colon (":"; i.e., the same format that Unix getopt() uses).
Note: Unlike GNU getopt(), after a non-option argument, all further arguments are considered also non-options. This is similar to the way non-GNU Unix systems work.
long_options, if specified, must be a list of strings with the names of the long options which should be supported. The leading '--' characters should not be included in the option name. Long options which require an argument should be followed by an equal sign ("="). To accept only long options, options should be an empty string. Long options on the command line can be recognized so long as they provide a prefix of the option name that matches exactly one of the accepted options. For example, if long_options is ['foo', 'frob'], the option --fo will match as --foo, but --f will not match uniquely, so GetoptError will be raised.
The return value consists of two elements: the first is a list of (option, value) pairs; the second is the list of program arguments left after the option list was stripped (this is a trailing slice of args). Each option-and-value pair returned has the option as its first element, prefixed with a hyphen for short options (e.g., '-x') or two hyphens for long options (e.g., '--long-option'), and the option argument as its second element, or an empty string if the option has no argument. The options occur in the list in the same order in which they were found, thus allowing multiple occurrences. Long and short options may be mixed.
gnu_getopt( args, options[, long_options])
This function works like getopt(), except that GNU style scanning mode is used by default. This means that option and non-option arguments may be intermixed. The getopt() function stops processing options as soon as a non-option argument is encountered.
If the first character of the option string is `+', or if the environment variable POSIXLY_CORRECT is set, then option processing stops as soon as a non-option argument is encountered.
New in version 2.3.
exception GetoptError
This is raised when an unrecognized option is found in the argument list or when an option requiring an argument is given none. The argument to the exception is a string indicating the cause of the error. For long options, an argument given to an option which does not require one will also cause this exception to be raised. The attributes msg and opt give the error message and related option; if there is no specific option to which the exception relates, opt is an empty string.
Changed in version 1.6: Introduced GetoptError as a synonym for error.
exception error
Alias for GetoptError; for backward compatibility.
An example using only Unix style options:
>>> import getopt
>>> args = '-a -b -cfoo -d bar a1 a2'.split()
>>> args
['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2']
>>> optlist, args = getopt.getopt(args, 'abc:d:')
>>> optlist
[('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')]
>>> args
['a1', 'a2']
Using long option names is equally easy:
>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
>>> args = s.split()
>>> args
['--condition=foo', '--testing', '--output-file', 'abc.def', '-x', 'a1', 'a2']
>>> optlist, args = getopt.getopt(args, 'x', [
... 'condition=', 'output-file=', 'testing'])
>>> optlist
[('--condition', 'foo'), ('--testing', ''), ('--output-file', 'abc.def'), ('-x',
'')]
>>> args
['a1', 'a2']
In a script, typical usage is something like this:
import getopt, sys def main(): try: opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="]) except getopt.GetoptError, err: # print help information and exit: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) output = None verbose = False for o, a in opts: if o == "-v": verbose = True elif o in ("-h", "--help"): usage() sys.exit() elif o in ("-o", "--output"): output = a else: assert False, "unhandled option" # ... if __name__ == "__main__": main()
发表评论
-
用python ctypes调用动态链接库
2009-10-12 15:10 7004ctypes is very cool! Great piec ... -
MoinMoin 1.5.8 上传附件的XMLRPC API实现
2009-09-22 16:44 2566一、服务端 1. 修改/usr/lib/python2.5/ ... -
用python实现SSH的免密码输入访问客户端
2009-07-10 09:52 84301. pexpect - http://pexpect.sou ... -
为心爱的MoinMoin写一个小小的Done宏
2009-04-15 16:04 1524############################# ... -
根据CSV文件自动形成表格的MoinMoin插件——InsertCSV
2009-02-28 00:34 3118MoinMoin本身的制表语法很简单,但是如果其他软件制作好的 ... -
使用appscript+python来控制Mac下的GUI应用程序
2009-02-15 13:28 8642在Mac下,appscript是一个与应用程序通信交互的强大工 ... -
PyFileMaker介绍
2009-02-15 11:57 1412PyFileMaker是一个用于访问和修改FileMaker ... -
如何将.py编译成.pyc/.pyo文件
2009-02-10 15:14 3795使用方式如下: python -O -m py_com ... -
Darwin Calendar Server,一个开放源代码的日历服务器
2009-02-06 19:18 3900Darwin Calendar Server是一个 ... -
VObject
2009-02-06 00:23 1174VObject VObject simplifies t ... -
python library extra
2009-02-06 00:18 9761. dateutil - The dateutil modu ... -
Epydoc
2009-02-05 12:15 1037http://epydoc.sourceforge.net/ ... -
一则魅族M8下歌词乱码的程序小故事
2009-01-20 00:41 2259最近,一朋友买了个魅族的M8手机,整天拨弄,爱不释手。一次找我 ... -
Jython 简单入门
2008-12-30 19:38 371211. 用Jython调用Java类库 第一步、创建Java类 ... -
readline
2008-12-02 23:33 1159There are two ways to configure ... -
feedparser学习摘要
2008-10-13 01:22 2971号称Universal Feed Parser,通吃所有合法不 ... -
py2exe 把python脚本转成windows下可执行文件
2008-10-12 23:42 3560py2exe是一个可以把python脚本转成windows下的 ... -
13.4 shelve -- Python object persistence
2008-10-05 02:22 1210import shelve d = shelve.o ... -
python相关拾零
2008-09-09 16:51 695* python-psycopg2 - Python modu ... -
TurboGears 和 Django 的比较
2008-08-21 22:50 7526TurboGears 和 Django 的比较 ...
相关推荐
java-getopt-1.0.14.jar
离线安装包,亲测可用
离线安装包,亲测可用
GNU GetOpt的Java端口 gnu.getopt/java-getopt/1.0.13/java-getopt-1.0.13.jar
getopt-php, 用于 命令行 参数处理的PHP库 GetOpt.PHP GetOpt.PHP 是命令行参数处理的库。 它支持PHP版本 5.4和更高版本。特性同时支持短( ( -v ) ) 和长( 例如。 --version ) 选项选项别名。IE 。选项既
在C编程中,`getopt()` 和 `getopt_long()` 是两个非常重要的函数,用于解析命令行选项。它们主要用于处理程序启动时用户输入的一系列参数,例如 `-h`(帮助)或 `-o`(带有参数的选项)。这些函数是C标准库的一部分...
Getopt-Alt 该模块提供了一个与 Getopt::Long 类似的接口,带有一些额外的扩展和语法现代化。 安装 要安装此模块,请运行以下命令: perl Build.PL ./Build ./Build test ./Build install SUPPORT AND DOCUMENTATION...
while ((opt = getopt_long(argc, argv, "vf:h", long_options, &opt_index)) != -1) { switch (opt) { case 'v': // 处理--verbose选项 break; case 'f': // 处理--file选项 break; case 'h': // 处理--...
升级程序,请阅读 命令行参数 一个成熟的,功能齐全的库,用于解析命令行选项。 概要 您可以使用主要的注释标准来设置选项()。 这些命令都是等效的,并设置相同的值: $ example --verbose --timeout=1000 --src ...
你可以考虑使用`std::parse_command_line`或`boost::program_options`等更现代的库来解析命令行参数,它们提供了更强大且更易用的API。 4. **自定义实现**:如果你的项目不需要跨平台,或者只需要简单的命令行解析...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
离线安装包,亲测可用
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装