当前位置: 首页 > news >正文

网站如何做等级保护太原做网页软件

网站如何做等级保护,太原做网页软件,做废铝的关注哪个网站好,3d模型网在运行程序时#xff0c;可能需要根据不同的条件#xff0c;输入不同的命令行选项来实现不同的功能。目前有短选项和长选项两种格式。短选项格式为-加上单个字母选项#xff1b;长选项为--加上一个单词。长格式是在Linux下引入的。许多Linux程序都支…在运行程序时可能需要根据不同的条件输入不同的命令行选项来实现不同的功能。目前有短选项和长选项两种格式。短选项格式为-加上单个字母选项长选项为--加上一个单词。长格式是在Linux下引入的。许多Linux程序都支持这两种格式。在Python中提供了getopt模块很好的实现了对这两种用法的支持而且使用简单。 取得命令行参数   在使用之前首先要取得命令行参数。使用sys模块可以得到命令行参数。 import sys print sys.argv   然后在命令行下敲入任意的参数如 python get.py -o t --help cmd file1 file2   结果为 [get.py, -o, t, --help, cmd, file1, file2]   可见所有命令行参数以空格为分隔符都保存在了sys.argv列表中。其中第1个为脚本的文件名。 选项的写法要求   对于短格式-号后面要紧跟一个选项字母。如果还有此选项的附加参数可以用空格分开也可以不分开。长度任意可以用引号。如以下是正确的 -o -oa -obbbb -o bbbb -o a b   对于长格式--号后面要跟一个单词。如果还有些选项的附加参数后面要紧跟再加上参数。号前后不能有空格。如以下是正确的 --helpfile1   而这些是不正确的 -- helpfile1 --help file1 --help file1 --help file1 如何用getopt进行分析   使用getopt模块分析命令行参数大体上分为三个步骤 1.导入getopt, sys模块 2.分析命令行参数 3.处理结果   第一步很简单只需要 import getopt, sys   第二步处理方法如下以Python手册上的例子为例 try:     opts, args getopt.getopt(sys.argv[1:], ho:, [help, output]) except getopt.GetoptError:     # print help information and exit: 1. 处理所使用的函数叫getopt()因为是直接使用import导入的getopt模块所以要加上限定getopt才可以。 2. 使用sys.argv[1:]过滤掉第一个参数它是执行脚本的名字不应算作参数的一部分。 3. 使用短格式分析串ho:。当一个选项只是表示开关状态时即后面不带附加参数时在分析串中写入选项字符。当选项后面是带一个附加参数时在分析串中写入选项字符同时后面加一个:号。所以ho:就表示h是一个开关选项o:则表示后面应该带一个参数。 4. 使用长格式分析串列表[help, output]。长格式串也可以有开关状态即后面不跟号。如果跟一个等号则表示后面还应有一个参数。这个长格式表示help是一个开关选项output则表示后面应该带一个参数。 5. 调用getopt函数。函数返回两个列表opts和args。opts为分析出的格式信息。args为不属于格式信息的剩余的命令行参数。opts是一个两元组的列表。每个元素为(选项串,附加参数)。如果没有附加参数则为空串。 6. 整个过程使用异常来包含这样当分析出错时就可以打印出使用信息来通知用户如何使用这个程序。   如上面解释的一个命令行例子为 -h -o file --help --outputout file1 file2   在分析完成后opts应该是 [(-h, ), (-o, file), (--help, ), (--output, out)]   而args则为 [file1, file2]   第三步主要是对分析出的参数进行判断是否存在然后再进一步处理。主要的处理模式为 for o, a in opts:     if o in (-h, --help):         usage()         sys.exit()     if o in (-o, --output):         output a   使用一个循环每次从opts中取出一个两元组赋给两个变量。o保存选项参数a为附加参数。接着对取出的选项参数进行处理。例子也采用手册的例子 http://docs.python.org/2/library/getopt.html 15.6.getopt— C-style parser for command line options Note Thegetoptmodule is a parser for command line options whose API is designed to be familiar to users of the Cgetopt()function. Users who are unfamiliar with the Cgetopt()function or who would like to write less code and get better help and error messages should consider using the argparse module instead. This module helps scripts to parse the command line arguments insys.argv. It supports the same conventions as the Unixgetopt()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. A more convenient, flexible, and powerful alternative is the optparse module. This module provides two functions and an exception: getopt.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 meanssys.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 Unixgetopt()uses). Note Unlike GNUgetopt(), 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 (). Optional arguments are not supported. 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_optionsis[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. getopt.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. exceptiongetopt.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 attributesmsgandoptgive the error message and related option; if there is no specific option to which the exception relates,optis an empty string. Changed in version 1.6: Introduced GetoptError as a synonym for error. exceptiongetopt.errorAlias for  GetoptError ; for backward compatibility. An example using only Unix style options: import getoptargs -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 --conditionfoo --testing --output-file abc.def -x a1 a2args s.split()args [--conditionfoo, --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, sysdef main():try:opts, args getopt.getopt(sys.argv[1:], ho:v, [help, output])except getopt.GetoptError as err:# print help information and exit:print str(err) # will print something like option -a not recognizedusage()sys.exit(2)output Noneverbose Falsefor o, a in opts:if o -v:verbose Trueelif o in (-h, --help):usage()sys.exit()elif o in (-o, --output):output aelse:assert False, unhandled option# ...if __name__ __main__:main() Note that an equivalent command line interface could be produced with less code and more informative help and error messages by using the argparse module: import argparseif __name__ __main__:parser argparse.ArgumentParser()parser.add_argument(-o, --output)parser.add_argument(-v, destverbose, actionstore_true)args parser.parse_args()# ... do something with args.output ...# ... do something with args.verbose ..
http://www.zqtcl.cn/news/163722/

相关文章:

  • 网站怎样做百度推广机关门户网站建设要求
  • 好看的网站后台模板沧州网站群
  • 深圳做网站排名公司哪家好哪些网站seo做的好
  • 国内网站建设推荐网站建设合同标准版
  • 哈尔滨网站制作费用企业成品网站模板
  • 网络广告网站怎么做北京海淀建设中路哪打疫苗
  • 房地产公司网站制作电影发布网站模板
  • 如何利用开源代码做网站网站本科
  • 公司是做小程序还是做网站宜宾住房与城乡建设部网站
  • 做网站哪个公司最社区问答网站开发
  • 网站引量方法网站建设推广页
  • 书店网站的建设网络营销方法有哪些
  • 深圳网站优化软件顺企网怎么样
  • 做网站的需要什么要求中国五百强企业排名表
  • 网络营销 企业网站外贸响应式网站建设
  • 网站网页制作公司o2o平台是什么意思啊
  • 惠州市网站建设个人网站怎么进入后台维护
  • 微信网站链接怎么做wordpress 绑定手机版
  • 网站建设的内容是什么在线阅读小说网站怎么建设
  • 福州网站开发哪家比较好建设网站需要掌握什么编程语言
  • 邹平做网站的公司莱芜人才网莱芜招聘
  • 旅行网站开发意义怎样优化网络速度
  • 手机微网站建设多少钱拟定网络设计方案
  • 厦门制作公司网站安卓原生app开发工具
  • worldpress英文网站建设wordpress输出外部文章
  • u9u8网站建设商业公司的域名
  • 有学给宝宝做衣服的网站吗防网站黑客
  • 十大搜索引擎网站微信小程序有什么用处?
  • 团购网站 seo烟台网站建设方案优化
  • 公司网站建设招标文件范本公益永久免费主机