PEP提议optparse

扫码查看
Hi,I would like to know your thoughts on a proposed change to optparsethat I have planned. It is possible to add default values to multipleoptions using the set_defaults. However, when adding descriptions tooptions the developer has to specify it in each add_option() call.This results in unreadable code such as:parser.add_option(''-q'', ''--quiet'' , action="store_false",dest=''verbose'',help = ''Output less information'')parser.add_option(''-o'', ''--output'' , type=''string'',dest=''castordir'' , metavar=''<DIR>'' ,help = ''specify the wanted CASTOR directory where to store theresults tarball'')parser.add_option(''-r'', ''--prevrel'' , type=''string'',dest=''previousrel'' , metavar=''<DIR>'' ,help = ''Top level dir of previous release for regressionanalysis'' )The same code could become much more readable if there was anequivalent method of set_defaults for the description/help of theoption. The same code could then become:parser.set_description(verbose = ''Output less information'',castordir = ''specify the wanted CASTOR directory whereto store the results tarball'',previousrel = ''Top level dir of previous release forregression analysis'')parser.add_option(''-q'', ''--quiet'' , action="store_false",dest=''verbose'')parser.add_option(''-o'', ''--output'' , type=''string'',dest=''castordir'' , metavar=''<DIR>'' )parser.add_option(''-r'', ''--prevrel'' , type=''string'',dest=''previousrel'' , metavar=''<DIR>'' )Help descriptions can often be quite long and separating them in thisfashion would, IMHO, be desirable.Kind Regards,James Nicolson 解决方案------ "Problems are solved by method"------ "Problems are solved by method"given that it only relies on indentation from the left margin, it''s noless readable in a proportional font (unless you''re using an font withvariable-width spaces, that is ;-).</F> 这篇关于PEP提议optparse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 01:37
查看更多