2007年10月13日 星期六 21:38
Ã÷Ã÷¿´µ½pydoc£¨http://docs.python.org/lib/optparse-tutorial.html£©ÉÏ˵¿ÉÒÔÕâôд: Then you can start defining options. The basic syntax is: parser.add_option(opt_str, ..., attr=value, ...) Each option has one or more option strings, such as "-f" or "-file", and several option attributes that tell optparse what to expect and what to do when it encounters that option on the command line. ¿ÉÊÇÔËÐÐʱÌáʾ˵invalid long option string '-file' ³öÎÊÌâµÄÄÇÒ»ÐУº parser.add_option("-f", "-file", "--file", dest="filename", help="write report to FILE", metavar="FILE") ÇëÎÊÔõô»ØÊ£¿ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071013/c2a1aca5/attachment.htm
2007年10月14日 星期日 11:39
On 10/13/07, Zhou Honglin <zhou.honglin在gmail.com> wrote: > 明明看到pydoc(http://docs.python.org/lib/optparse-tutorial.html)上说可以这么写: > Then you can start defining options. The basic syntax is: > parser.add_option(opt_str, ..., > attr=value, ...) > > > > Each option has one or more option strings, such as "-f" or "-file", and > several option attributes that tell optparse what to expect and what to do > when it encounters that option on the command line. > > 可是运行时提示说invalid long option string '-file' > 出问题的那一行: > > parser.add_option("-f", "-file", "--file", dest="filename", > help="write report to FILE", metavar="FILE") > > 请问怎么回事? > 单个字母的参数一般使用一个'-'号,而多字母的参数使用'--',好象很少见到有单个'-'的多字母参数 -- I like python! UliPad <>: http://code.google.com/p/ulipad/ meide < >: http://code.google.com/p/meide/ My Blog: http://www.donews.net/limodou
2007年10月14日 星期日 11:58
在 07-10-13,Zhou Honglin<zhou.honglin在gmail.com> 写道: > 明明看到pydoc(http://docs.python.org/lib/optparse-tutorial.html)上说可以这么写: > Then you can start defining options. The basic syntax is: > parser.add_option(opt_str, ..., > attr=value, ...) > > > > Each option has one or more option strings, such as "-f" or "-file", and > several option attributes that tell optparse what to expect and what to do > when it encounters that option on the command line. > > 可是运行时提示说invalid long option string '-file' > 出问题的那一行: > > parser.add_option("-f", "-file", "--file", dest="filename", > help="write report to FILE", metavar="FILE") > > 请问怎么回事? 说明是 pydoc 说错了 ^_^
2007年10月14日 星期日 14:20
×î½üҪǨÒƵÄÒ»¸öLinux³ÌÐòÃüÁîÐж̿ª¹Ø¶¼ÊÇÀàËÆ-ex -fileÖ®ÀàµÄ¡¡¿´Ñù×ÓÖ»ºÃÊÖдһ²¿·ÖparserÁË:( On 10/14/07, XiaQ <xiaqqaix在gmail.com> wrote: > > ÔÚ 07-10-13£¬Zhou Honglin<zhou.honglin在gmail.com> дµÀ£º > > Ã÷Ã÷¿´µ½pydoc£¨http://docs.python.org/lib/optparse-tutorial.html£©ÉÏ˵¿ÉÒÔÕâôд: > > Then you can start defining options. The basic syntax is: > > parser.add_option(opt_str, ..., > > attr=value, ...) > > > > > > > > Each option has one or more option strings, such as "-f" or "-file", > and > > several option attributes that tell optparse what to expect and what to > do > > when it encounters that option on the command line. > > > > ¿ÉÊÇÔËÐÐʱÌáʾ˵invalid long option string '-file' > > ³öÎÊÌâµÄÄÇÒ»ÐУº > > > > parser.add_option("-f", "-file", "--file", dest="filename", > > help="write report to FILE", metavar="FILE") > > > > ÇëÎÊÔõô»ØÊ£¿ > > ˵Ã÷ÊÇ pydoc ˵´íÁË ^_^ > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071014/17606100/attachment.html
2007年10月14日 星期日 14:46
自己做下替换, 把 -字母字母 替换成 --字母字母 再交给 optparse 在 07-10-14,Zhou Honglin<zhou.honglin at gmail.com> 写道: > > 最近要迁移的一个Linux程序命令行短开关都是类似-ex -file之类的……看样子只好手写一部分parser了:( >
2007年10月14日 星期日 15:56
ÎÒÊÇÕâÑùдµÄ£¬°Ñ-³¤×ÖĸÌæ»»³É-µ¥×Öĸ£¬²»ÖªµÀÓÐûÓиüºÃµÄд·¨£¿ trans_map = {"-ef":"-e", "-cf":"-c", "-sf":"-s", "-xf":"-x" } f = lambda arg: (arg in trans_map.keys() and trans_map[arg]) or arg args = [f(arg) for arg in sys.argv[1:] if arg in trans_map.keys()] On 10/14/07, Jiahua Huang <jhuangjiahua在gmail.com> wrote: > > ×Ô¼º×öÏÂÌæ»»£¬ > °Ñ -×Öĸ×Öĸ Ìæ»»³É --×Öĸ×Öĸ > ÔÙ½»¸ø optparse > > ÔÚ 07-10-14£¬Zhou Honglin<zhou.honglin在gmail.com> дµÀ£º > > > > ×î½üҪǨÒƵÄÒ»¸öLinux³ÌÐòÃüÁîÐж̿ª¹Ø¶¼ÊÇÀàËÆ-ex -fileÖ®ÀàµÄ¡¡¿´Ñù×ÓÖ»ºÃÊÖдһ²¿·ÖparserÁË:( > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071014/7467c873/attachment.htm
2007年10月14日 星期日 16:27
把 -长字母 替换为 -- 长字母(两个-) arg = map(lambda i: re.sub(r'(^-[a-z]{2})',r'-\1',i), arg) 再解析长字母 在 07-10-14,Zhou Honglin<zhou.honglin at gmail.com> 写道: > > > 我是这样写的,把-长字母替换成-单字母,不知道有没有更好的写法? >
2007年10月16日 星期二 11:58
лл¡« On 10/14/07, Jiahua Huang <jhuangjiahua在gmail.com> wrote: > > °Ñ -³¤×Öĸ Ì滻Ϊ -- ³¤×Öĸ(Á½¸ö-) > arg = map(lambda i: re.sub(r'(^-[a-z]{2})',r'-\1',i), arg) > ÔÙ½âÎö³¤×Öĸ > > ÔÚ 07-10-14£¬Zhou Honglin<zhou.honglin在gmail.com> дµÀ£º > > > > > > ÎÒÊÇÕâÑùдµÄ£¬°Ñ-³¤×ÖĸÌæ»»³É-µ¥×Öĸ£¬²»ÖªµÀÓÐûÓиüºÃµÄд·¨£¿ > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071016/195b61a2/attachment.htm
Zeuux © 2025
京ICP备05028076号