Re: python 写命令行程序

shhgs <[email protected]>
Newsgroups gmane.comp.python.chinese
Message-ID <[email protected]>
难道没人知道optparse吗?



2008/1/17 tairan wang <[email protected]>:
>
> 收到!
>
> Thanks
>
>
>
> ________________________________
> > Date: Thu, 17 Jan 2008 12:27:34 +0800
> > From: [email protected]
> > To: [email protected]
> > Subject: Re: [python-chinese] python 写命令行程序
>
>
> >
> > copy一段我的,
> > try:
> > opts, args = getopt.getopt(sys.argv[1:], "hs:t:b:", ["help",
> > "site=","build=","type="])
> > #支持长选项和短选项两个方式,之所短的: "hs:t:b:"表示-h是开关类型的选项,-s,-t,-t是需要提供额外的值。
> > #比如: cmd.py -s www.google.com -t homepage -b other_args 或者
> > #cmd.py -h 或者 cmd.py --help
> > #opts包含(opt,value)这样的选项和值
> > #args包含参数列表
> > except getopt.GetoptError, err:
> > # print help information and exit:
> > print str(err) # will print something like "option -a not recognized"
> > usage()
> > sys.exit(2)
> > for o, a in opts:
> > if o in ("-h", "--help"):
> > usage()
> > sys.exit()
> > elif o in ("-o", "--output"):
> > output = a
> > elif o in ("-s","--site") :
> > site_alias = a
> > elif o in ("-t","--type"):
> > build_type = a
> > elif o in ("-b","--build"):
> > build_number = a
> > else:
> > assert False, "unhandled option"
> >
> > # ...
> > _______________________________________________
> > python-chinese
> > Post: send [email protected]
> > Subscribe: send subscribe to [email protected]
> > Unsubscribe: send unsubscribe to [email protected]
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
> ________________________________
> Express yourself instantly with MSN Messenger! MSN Messenger
> _______________________________________________
> python-chinese
> Post: send [email protected]
> Subscribe: send subscribe to [email protected]
> Unsubscribe: send unsubscribe to  [email protected]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
_______________________________________________
python-chinese
Post: send [email protected]
Subscribe: send subscribe to [email protected]
Unsubscribe: send unsubscribe to  [email protected]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.