From 22948d838fa22c160682419b4be9be7f421c5e39 Mon Sep 17 00:00:00 2001 From: "steven.bethard" Date: Sun, 28 Feb 2010 06:49:22 +0000 Subject: Deprecate ArgumentParser(..., version=XXX, ...) as well as format_version() and print_version(). These should be replaced with .add_argument(..., action='version', ...). --- doc/ArgumentParser.html | 20 +------------------- doc/add_argument.html | 6 +++--- doc/api-docs.html | 1 - doc/searchindex.js | 2 +- doc/source/ArgumentParser.rst | 21 +-------------------- doc/source/add_argument.rst | 6 +++--- 6 files changed, 9 insertions(+), 47 deletions(-) (limited to 'doc') diff --git a/doc/ArgumentParser.html b/doc/ArgumentParser.html index fc8df9d..f7e37ee 100644 --- a/doc/ArgumentParser.html +++ b/doc/ArgumentParser.html @@ -52,12 +52,11 @@
-class ArgumentParser([description][, epilog][, prog][, usage][, version][, add_help][, argument_default][, parents][, prefix_chars][, conflict_handler][, formatter_class])
+class ArgumentParser([description][, epilog][, prog][, usage][, add_help][, argument_default][, parents][, prefix_chars][, conflict_handler][, formatter_class])

Create a new ArgumentParser object. Each parameter has its own more detailed description below, but in short they are:

  • description - Text to display before the argument help.
  • epilog - Text to display after the argument help.
  • -
  • version - A version number used to add a -v/–version option to the parser.
  • add_help - Add a -h/–help option to the parser. (default: True)
  • argument_default - Set the global default value for arguments. (default: None)
  • parents - A list of :class:ArgumentParser objects whose arguments should also be included.
  • @@ -105,22 +104,6 @@ class ArgumentParser(description argument, the epilog= text is by default line-wrapped, but this behavior can be adjusted with the formatter_class argument to ArgumentParser.

    -
    -

    version

    -

    Programs which want to display the program version at the command line can supply a version message as the version= argument to ArgumentParser. This will add a -v/--version option to the ArgumentParser that can be invoked to print the version string:

    -
    >>> parser = argparse.ArgumentParser(prog='PROG', version='%(prog)s 3.5')
    ->>> parser.print_help()
    -usage: PROG [-h] [-v]
    -
    -optional arguments:
    -  -h, --help     show this help message and exit
    -  -v, --version  show program's version number and exit
    ->>> parser.parse_args(['-v'])
    -PROG 3.5
    -
    -
    -

    Note you can use the %(prog)s format specifier to insert the program name into the version string. For greater customization, see the documentation on the 'version' action available for add_argument().

    -

    add_help

    By default, ArgumentParser objects add a -h/--help option which simply displays the parser’s help message. For example, consider a file named myprogram.py containing the following code:

    @@ -396,7 +379,6 @@ optional arguments:
  • ArgumentParser objects
  • -
  • 'version' - This expects a version= keyword argument in the add_argument() call, and prints version information and exits when invoked. This can be used when the default ArgumentParser version flags -v, --version are not appropriate for your program.

    +
  • 'version' - This expects a version= keyword argument in the add_argument() call, and prints version information and exits when invoked.

    >>> import argparse
     >>> parser = argparse.ArgumentParser(prog='PROG')
    ->>> parser.add_argument('-V', action='version', version='%(prog)s 2.0')
    ->>> parser.parse_args(['-V'])
    +>>> parser.add_argument('-v', '--version', action='version', version='%(prog)s 2.0')
    +>>> parser.parse_args(['-v'])
     PROG 2.0
     
    diff --git a/doc/api-docs.html b/doc/api-docs.html index eadfbe0..e257716 100644 --- a/doc/api-docs.html +++ b/doc/api-docs.html @@ -51,7 +51,6 @@
  • ArgumentParser objects
    • description
    • epilog
    • -
    • version
    • add_help
    • prefix_chars
    • fromfile_prefix_chars
    • diff --git a/doc/searchindex.js b/doc/searchindex.js index 3a561be..080fc79 100644 --- a/doc/searchindex.js +++ b/doc/searchindex.js @@ -1 +1 @@ -Search.setIndex({desctypes:{"0":"method","1":"class"},terms:{all:[6,3,7,5,2],code:[0,7,6],partial:[8,7,2],messg:7,whatev:2,illustr:[7,5],global:6,four:5,prefix:[1,6,5],subclass:2,follow:[0,7,5,6,3],formatter_class:[8,6],whose:[5,6],typeerror:[],"const":[8,3,7,1,5],fancier:2,readabl:4,prefix_char:[8,7,6],program:[6,0,5,2,3],present:[7,1,2,5],sens:[5,6],worth:5,consum:[7,5],everi:3,string:[1,2,3,5,6,7],fals:[6,7,5,2],subcommand:[7,2],util:[8,0,4],parent_pars:6,retriev:[],default_:[],exact:7,implement:5,level:2,list:[1,2,3,5,6,7],"try":[7,6],item:[5,2],adjust:6,stderr:2,pleas:6,subparser_nam:2,bacon:1,dogmat:7,past:7,zero:[7,5],fyoyo:7,group1:2,pass:[1,2,4,5,6,7],append:5,compat:7,what:[3,7,1,6,5],abc:[7,5],sub:[8,7,2],neg:1,section:[6,7,5,2],advanc:7,brief:[6,5,2],current:[6,2],abbrevi:[8,1],version:[8,5,6],"new":[7,1,6,5],method:[0,1,2,3,5,6,7,8],told:5,deriv:[7,5],gener:[0,7,5,6,3],never:[7,6],here:[7,1],let:2,inher:1,path:7,along:1,infil:[4,5],modifi:2,sinc:7,interpret:5,convert:[3,4,7,1,5],produc:[7,5,2],convers:5,pick:1,action:[1,2,3,5,6,7,8],weird:6,commonli:5,mutual:[8,2],control:6,regardless:6,extra:[1,2],appli:5,modul:[0,7,5,3],prefer:7,filenam:5,api:[8,0,7,5],txt:[0,5,6],select:[5,2],add_argument_group:2,from:[1,2,3,5,6,7],describ:[6,5,2],would:[7,5],frobbl:[5,2],regist:2,two:[6,3,1,2,5],few:[7,5,2],call:[0,1,2,3,5,6,7],add_help:[8,7,6,2],recommend:2,taken:[7,1,5],rawtexthelpformatt:6,type:[0,1,2,3,4,5,6,7,8],tell:[3,1],more:[0,1,3,5,6,7],sort:[3,5,6],parser_a:2,parser_b:2,notic:[7,1],warn:5,flag:[8,7,5],indic:[6,5,2],particular:[7,5,2],known:7,hold:[3,5],easiest:[7,5,2],must:[1,6,5],dictat:7,none:[4,7,1,6,5],word:[6,2],dest:[1,2,3,5,7,8],work:[6,2],conceptu:2,remain:[3,7,5,2],itself:5,can:[0,1,2,3,4,5,6,7],def:[7,5,2],overrid:[7,6,2],traceback:6,prompt:1,puriti:7,give:[1,6],frabbl:3,share:[7,6],add_argu:[0,1,2,3,4,5,6,7,8],accept:[7,5,2],cautiou:1,want:[6,3,7,5,2],alwai:[6,5,2],multipl:[7,5,2],thing:5,rather:[1,6],anoth:[6,5,2],check_method:7,fooaction:[7,5],write:[0,7,6,3],how:[6,3,1,2,5],sever:[6,1,2],instead:[7,5,2],narg:[0,1,3,5,6,7,8],simpl:[0,7,5,3],updat:2,parser_abc:7,foo_pars:[7,6],overridden:6,mess:6,max:[3,1],after:[6,7,1,2,5],variant:2,invok:[6,3,7,5,2],befor:[5,6],wrong:1,okai:6,mai:[6,7,1,2,5],end:[7,5,2],associ:[5,2],xfoox:7,"0x013a2410":[],"short":[1,6,5],attempt:[7,1],practic:7,stdin:[4,5],explicit:5,correspond:[3,7],ambigu:1,caus:[5,6],inform:[6,3,7,5,2],type_:[],maintain:[7,6],combin:[1,2],allow:[6,7,1,2,5],callabl:[7,5],order:2,origin:[7,6],least:[5,2],help:[0,1,2,3,5,6,7,8],over:[7,6],becaus:6,through:7,same:[7,5,6],hierarchi:7,metavar_:[],still:5,subparser2:2,subparser1:2,paramet:[7,5,6],perfect:5,style:1,interspers:7,group:[8,2],fit:6,better:[7,2],main:2,easier:1,them:[0,5,1,6,3],good:2,"return":[3,7,1,2,5],greater:6,thei:[7,1,6,5],python:[0,7,6,2],initi:[3,5],option_str:[7,5],now:[3,7],discuss:7,introduct:[0,3],choic:[1,2,3,5,7,8],allow_interspersed_arg:7,optionerror:7,name:[1,2,3,5,6,7,8],anyth:[7,5],choices_:[],separ:[1,2],easili:7,achiev:[1,6],mode:[4,7,5],each:[6,3,7,5,2],fulli:2,difficult:7,nbar:6,mean:[3,7,5,6],myprogram:6,replac:[7,6],idea:2,heavi:1,expect:[3,1,5],our:3,happen:7,beyond:[8,1],metavar:[0,1,3,5,7,8],special:[5,2],out:[0,4,5,6,3],variabl:7,accomplish:[1,6],referenc:6,space:[6,2],foo_bar:5,newli:1,parser_xyz:7,perfect_squar:5,print:[1,2,3,5,6,7,8],factori:[4,5],math:5,common:[3,5,6],optionvalueerror:7,worthwhil:7,situat:[1,5],given:6,argv:[8,3,1,6],standard:7,mmm:1,reason:7,base:7,dictionari:7,care:[7,2],indent:6,could:[1,5],omit:5,refus:7,keep:6,fromfile_prefix_char:[8,6,2],turn:3,place:6,isn:[7,5],retain:6,const_:[],assign:1,first:[5,6],oper:5,rang:[3,1],directli:5,carri:3,onc:[3,2],number:[6,7,1,2,5],restrict:5,instruct:3,alreadi:[7,1,6],construct:[7,6],wasn:5,open:[4,7,5,6],size:4,differ:[7,5,2],script:[3,2],top:2,sometim:[6,1,2],messag:[0,1,2,5,6,7],too:5,similarli:2,conveni:[7,5],"final":[],store:[3,5],monkei:7,option:[0,1,2,3,5,6,7,8],namespac:[1,2,3,4,5,6,7,8],copi:7,specifi:[0,1,2,3,5,6,7],pars:[0,1,2,3,5,7,8],store_tru:[3,7,1,2,5],exactli:[3,1,6],than:[6,7,1,2,5],format_usag:2,wide:6,kind:2,setattr:[7,5],whenev:[1,5],provid:[0,7,1,2,5],remov:6,charact:[7,1,6,5],str:5,were:[5,6],posit:[0,1,2,3,5,6,7],seri:[3,5],sai:7,abov:[6,0,1,2,3],"0x013a2380":[],group2:2,argument:[0,1,2,3,4,5,6,7,8],dash:7,add_pars:[7,2],manner:[3,7],have:[4,7,1,6,5],"__main__":[0,3],need:[6,7,5,2],seem:7,squar:5,equival:6,callback:7,self:[7,5,2],append_const:5,also:[6,1,2,5],builtin:5,exampl:[0,1,2,3,5,6],take:[1,2,3,5,6,7],which:[6,7,1,2,5],singl:[1,2,3,5,6,7],uppercas:5,begin:[3,1],sure:[7,5,2],though:5,buffer:4,previou:[7,1],most:[6,3,7,5,2],regular:2,pair:[7,6],choos:[7,5],"class":[4,7,1,6,5],appear:2,don:[7,1,5],later:3,request:[4,5,2],doe:[6,7,5,2],declar:7,determin:[1,2,3,5,6,7],occasion:6,sum:[0,1,3],"0x00b8fb18":[],parser_bar:2,show:[6,0,7,5,2],text:6,filetyp:[8,0,4,5],syntax:[8,7,1],particularli:[7,6,2],hack:7,find:[3,1,2],onli:[6,7,1,2,5],textual:6,parse_known_arg:2,just:[5,2],pretti:3,"true":[1,2,3,5,6,7],parser_foo:2,figur:5,should:[0,2,3,5,6,7],store_const:[3,7,1,5],wood:1,dict:5,"__call__":[7,5],add_opt:7,variou:[5,6],get:[6,3,7,1,2],express:6,report:5,requir:[8,7,1,2,5],bar:[1,2,3,5,6,7],keyword:[1,2,3,5,6,7],baz:[7,5,2],dramat:7,yield:2,patch:7,store_fals:[5,2],whether:[5,6],bad:[1,5],calcul:6,bac:1,contain:[1,2,5,6,7,8],where:[0,5,6],set:[6,3,7,5,2],"float":[7,5,2],see:[1,2,3,5,6,7],arg:[0,1,2,3,4,5,6,7],close:0,extend:[7,5],correctli:6,someth:3,written:0,subdir:6,between:6,"import":[0,7,5,6,3],awai:5,badger:[7,1,2],across:6,attribut:[1,2,3,5,6,7],altern:6,parent:[8,7,6,2],xrang:[3,7,1,5],disallow:[7,6],extens:7,outfil:5,come:7,addit:[6,7,5,2],both:[7,1],last:[1,6],howev:[6,7,5,2],against:7,etc:[7,1,2,5],eas:5,mani:[7,5],whole:[],simpli:[6,7,1,2,5],point:7,argumentpars:[0,1,2,3,4,5,6,7,8],dispatch:7,featur:7,suppli:[6,3,7,5,2],respect:5,assum:[0,5,2,3],duplic:7,quit:[7,5],coupl:[6,2],addition:5,three:6,empti:1,implicit:7,accumul:[3,1],secret:7,much:[3,7,1,2,5],valu:[1,2,5,6,7,8],basic:5,unambigu:1,print_usag:2,popul:[1,2],strategi:6,epilog:[8,6],suppress:[7,5,6],xxx:[7,5,6],great:5,ani:[6,7,5,2],upgrad:[0,7],understand:4,togeth:[1,5],func:2,child:6,repetit:5,those:[7,1],"case":[3,1,2,5],therefor:5,look:[3,7,1],format_help:2,formatt:6,defin:[6,5,2],"while":[7,1,6,5],behavior:[3,5,6],error:[6,7,1,2,5],argpars:[0,1,2,3,4,5,6,7],advantag:[0,7],stdout:[0,4,5],almost:[5,6],kwarg:[7,2],arg_lin:2,"__init__":7,clearli:1,perform:[5,2],make:[6,3,7,5,2],format:[6,7,5,2],sqrt:5,check:[7,1,2,5],handl:[7,5,2],complex:[7,5],help_:[],split:[1,2,3,5,6,7],document:[8,0,1,6],infer:5,dest_:[],complet:2,dedent:6,foo_bar_baz_pars:7,effect:2,rais:[5,6],user:[6,7,1,2,5],store_act:7,typic:[3,7,5,2],recent:6,appropri:[0,2,3,5,6,7],older:6,argumenttypeerror:5,thu:7,inherit:[7,6],likewis:6,without:2,command:[0,1,2,3,4,5,6,7,8],thi:[0,1,2,3,4,5,6,7],conflict:6,everyth:[7,1],sibl:2,usual:[6,7,5,2],identifi:5,execut:2,add_mutually_exclusive_group:2,note:[6,7,5,2],action_:[],exclus:[8,2],expos:7,had:7,except:[6,2],add:[0,2,3,5,6,7],valid:[7,5,2],remaining_arg:7,rawdescriptionhelpformatt:6,save:[0,3],match:[6,7,1,2,5],applic:[6,2],transpar:7,read:[6,5,2],textwrap:6,writabl:[4,5],built:[3,1],know:[7,5,2],print_help:[6,7,5,2],like:[1,2,3,5,6,7],insert:[1,6],get_default:2,specif:6,arbitrari:5,whitespac:6,manual:7,resolv:6,integ:[0,5,7,1,3],collect:6,necessari:[3,7,5,2],either:[1,2,3,5,6,7],argumenterror:[7,6],output:[6,4,5,2],unnecessari:6,encount:[3,1,5],old:[6,2],often:5,"0x00b1f020":[],interact:1,some:[1,2,3,5,6,7],back:2,intern:5,mistak:1,proper:7,librari:7,absent:5,subpars:[7,2],avoid:5,normal:[1,2,5],definit:6,per:[6,2],exit:[0,1,2,5,6,7],prog:[1,2,5,6,7,8],foo:[1,2,3,5,6,7],refer:[1,6,5],nargs_:[],object:[0,1,2,3,4,5,6,7,8],run:[0,3],inspect:[3,2],usag:[0,1,2,5,6,7,8],argument_default:[8,6],found:1,add_subpars:[7,2],"__name__":[0,3],"super":7,xyzz:1,about:[6,3,7,5,2],actual:7,meth:[],callback_:7,optpars:[0,7],constructor:[7,6,2],commit:2,disabl:6,own:[6,7,5,2],xyz:[7,2],within:6,automat:[4,5,6],suppl:2,been:[3,7,5],strip:[5,2],wrap:6,chang:[6,7,5,2],mark:5,yyi:[5,6],your:[6,3,7,5,2],manag:3,inclus:5,fill:[3,6],log:0,wai:[6,7,1,2,5],spam:[7,1,2],support:[6,7,1,2,5],"long":[7,1,6,5],custom:[6,8,1,2,5],avail:[6,5,2],start:[3,6],interfac:[0,7,5,3],includ:[6,7,1,2,5],lot:[7,2],parse_arg:[0,1,2,3,4,5,6,7,8],treat:[6,2],"function":[1,2,5],reduc:7,creation:[6,2],form:[3,7,5],tupl:[5,2],bufsiz:[4,5],continu:2,msg:5,parents_:[],"0x00b8fe78":[],line:[0,1,2,3,4,5,6,7],conflict_handl:[8,6],concaten:1,made:1,input:5,temp:5,possibl:5,"default":[0,1,2,3,5,6,7,8],checkout:2,argumentdefaultshelpformatt:6,displai:[6,7,5,2],below:[7,5,6],otherwis:6,similar:7,gather:5,constant:5,creat:[0,1,2,3,4,5,6,7],"int":[0,1,2,3,5,6,7],descript:[0,2,3,5,6,8],parser:[0,1,2,3,4,5,6,7,8],"0x00b1f068":[],doesn:[7,5],strongli:2,exist:1,file:[0,2,3,4,5,6,7,8],xyzyx:2,simplest:1,probabl:5,again:7,readi:3,titl:2,when:[0,1,2,3,5,6,7],detail:[1,6,5],invalid:[8,7,1,5],other:[0,1,2,4,6,7,8],futur:2,scriptnam:0,varieti:1,test:7,set_default:[6,2],you:[1,2,3,5,6,7],bar_pars:[7,6],repeat:6,clean:6,why:7,consid:[5,6],"0x00adf020":[],svn:2,receiv:7,longer:[7,1,2],pseudo:[4,1],time:[7,5,2],backward:7,convert_arg_line_to_arg:[6,2]},titles:["Documentation","The parse_args() method","Other methods","Introduction to argparse","Other utilities","The add_argument() method","ArgumentParser objects","argparse vs. optparse","API documentation"],modules:{},descrefs:{"":{parse_args:[1,0],parse_known_args:[2,0],add_mutually_exclusive_group:[2,0],set_defaults:[2,0],FileType:[4,1],add_argument:[5,0],ArgumentParser:[6,1],convert_arg_line_to_args:[2,0],get_default:[2,0],add_subparsers:[2,0],add_argument_group:[2,0]}},filenames:["index","parse_args","other-methods","overview","other-utilities","add_argument","ArgumentParser","argparse-vs-optparse","api-docs"]}) \ No newline at end of file +Search.setIndex({desctypes:{"0":"method","1":"class"},terms:{all:[6,3,7,5,2],code:[0,7,6],partial:[8,7,2],messg:7,whatev:2,illustr:[7,5],global:6,four:5,prefix:[1,6,5],per:[6,2],follow:[0,7,5,6,3],concaten:1,formatter_class:[8,6],whose:[5,6],typeerror:[],"const":[8,3,7,1,5],fancier:2,readabl:4,prefix_char:[8,7,6],program:[6,0,5,2,3],those:[7,1],sens:[5,6],worth:5,consum:[7,5],everi:3,string:[1,2,3,5,6,7],fals:[6,7,5,2],subcommand:[7,2],util:[8,0,4],prog:[1,2,5,6,7,8],retriev:[],default_:[],exact:7,implement:5,level:2,list:[1,2,3,5,6,7],"try":[7,6],item:[5,2],adjust:6,stderr:2,pleas:6,subparser_nam:2,bacon:1,dogmat:7,past:7,zero:[7,5],fyoyo:7,group1:2,pass:[1,2,4,5,6,7],append:5,compat:7,what:[3,7,1,6,5],abc:[7,5],sub:[8,7,2],neg:1,section:[6,7,5,2],advanc:7,brief:[6,5,2],current:[6,2],abbrevi:[8,1],version:5,"new":[7,1,6,5],method:[0,1,2,3,5,6,7,8],told:5,deriv:[7,5],gener:[0,7,5,6,3],never:[7,6],here:[7,1],let:2,inher:1,path:7,along:1,standard:7,modifi:2,sinc:7,interpret:5,convert:[3,4,7,1,5],convers:5,later:3,pick:1,action:[1,2,3,5,6,7,8],weird:6,almost:[5,6],commonli:5,control:6,regardless:6,extra:[1,2],appli:5,modul:[0,7,5,3],prefer:7,"while":[7,1,6,5],filenam:5,api:[8,0,7,5],txt:[0,5,6],select:[5,2],add_argument_group:2,from:[1,2,3,5,6,7],describ:[6,5,2],would:[7,5],frobbl:[5,2],regist:2,two:[6,3,1,2,5],few:[7,5,2],call:[0,1,2,3,5,6,7],add_help:[8,7,6,2],recommend:2,taken:[7,1,5],care:[7,2],type:[0,1,2,3,4,5,6,7,8],tell:[3,1],more:[0,1,3,5,6,7],sort:[3,5,6],parser_a:2,parser_b:2,line:[0,1,2,3,4,5,6,7],notic:[7,1],warn:5,flag:[8,7,5],indic:[6,5,2],particular:[7,5,2],known:7,hold:[3,5],easiest:[7,5,2],must:[1,6,5],dictat:7,none:[4,7,1,6,5],word:[6,2],work:[6,2],conceptu:2,remain:[3,7,5,2],kwarg:[7,2],can:[0,1,2,3,4,5,6,7],def:[7,5,2],overrid:[7,6,2],omit:5,prompt:1,puriti:7,give:[1,6],frabbl:3,share:[7,6],add_argu:[0,1,2,3,4,5,6,7,8],accept:[7,5,2],cautiou:1,want:[6,3,7,5,2],alwai:[6,5,2],multipl:[7,5,2],turn:3,rather:[1,6],anoth:[6,5,2],check_method:7,fooaction:[7,5],write:[0,7,6,3],how:[6,3,1,2,5],"__init__":7,instead:[7,5,2],narg:[0,1,3,5,6,7,8],simpl:[0,7,5,3],updat:2,parser_abc:7,foo_pars:[7,6],referenc:6,mess:6,max:[3,1],after:[6,7,1,2,5],variant:2,befor:[5,6],wrong:1,okai:6,mai:[6,7,1,2,5],end:[7,5,2],associ:[5,2],xfoox:7,"0x013a2410":[],"short":[1,6,5],store_tru:[3,7,1,2,5],practic:7,read:[6,5,2],stdin:[4,5],explicit:5,correspond:[3,7],ambigu:1,caus:[5,6],inform:[6,3,7,5,2],type_:[],maintain:[7,6],combin:[1,2],allow:[6,7,1,2,5],callabl:[7,5],order:2,origin:[7,6],least:[5,2],help:[0,1,2,3,5,6,7,8],over:[7,6],becaus:6,through:7,sqrt:5,hierarchi:7,metavar_:[],still:5,subparser2:2,subparser1:2,paramet:[7,5,6],perfect:5,style:1,interspers:7,group:[8,2],fit:6,better:[7,2],main:2,easier:1,them:[0,5,1,6,3],good:2,"return":[3,7,1,2,5],greater:[],thei:[7,1,6,5],python:[0,7,6,2],initi:[3,5],option_str:[7,5],now:[3,7],discuss:7,introduct:[0,3],choic:[1,2,3,5,7,8],allow_interspersed_arg:7,optionerror:7,name:[1,2,3,5,6,7,8],anyth:[7,5],choices_:[],separ:[1,2],easili:7,achiev:[1,6],mode:[4,7,5],each:[6,3,7,5,2],fulli:2,complet:2,nbar:6,mean:[3,7,5,6],myprogram:6,replac:[7,6],idea:2,heavi:1,expect:[3,1,5],our:3,happen:7,beyond:[8,1],metavar:[0,1,3,5,7,8],special:[5,2],out:[0,4,5,6,3],variabl:7,accomplish:[1,6],overridden:6,space:[6,2],foo_bar:5,newli:1,parser_xyz:7,perfect_squar:5,print:[1,2,3,5,6,7,8],factori:[4,5],math:5,bac:1,optionvalueerror:7,worthwhil:7,situat:[1,5],given:6,argv:[8,3,1,6],infil:[4,5],mmm:1,reason:7,base:7,dictionari:7,rawtexthelpformatt:6,indent:6,could:[1,5],traceback:6,refus:7,keep:6,fromfile_prefix_char:[8,6,2],thing:5,place:6,isn:[7,5],retain:6,const_:[],assign:1,first:[5,6],oper:5,rang:[3,1],directli:5,carri:3,onc:[3,2],number:[7,1,2,5],restrict:5,instruct:3,alreadi:[7,1,6],construct:[7,6],wasn:5,open:[4,7,5,6],size:4,differ:[7,5,2],"long":[7,1,6,5],script:[3,2],top:2,sometim:[6,1,2],messag:[0,1,2,5,6,7],too:5,similarli:2,conveni:[7,5],"final":[],store:[3,5],monkei:7,option:[0,1,2,3,5,6,7,8],namespac:[1,2,3,4,5,6,7,8],copi:7,specifi:[0,1,2,3,5,6,7],pars:[0,1,2,3,5,7,8],attempt:[7,1],exactli:[3,1,6],than:[6,7,1,2,5],format_usag:2,wide:6,kind:2,setattr:[7,5],whenev:[1,5],provid:[0,7,1,2,5],remov:6,charact:[7,1,6,5],str:5,were:[5,6],posit:[0,1,2,3,5,6,7],seri:[3,5],sai:7,behavior:[3,5,6],"0x013a2380":[],group2:2,argument:[0,1,2,3,4,5,6,7,8],dash:7,add_pars:[7,2],manner:[3,7],have:[4,7,1,6,5],"__main__":[0,3],need:[6,7,5,2],seem:7,probabl:5,squar:5,equival:6,callback:7,self:[7,5,2],append_const:5,also:[6,1,2,5],builtin:5,without:2,take:[1,2,3,5,6,7],which:[6,7,1,2,5],singl:[1,2,3,5,6,7],uppercas:5,begin:[3,1],sure:[7,5,2],though:5,buffer:4,previou:[7,1],most:[6,3,7,5,2],regular:2,pair:[7,6],choos:[7,5],"class":[4,7,1,6,5],appear:2,don:[7,1,5],gather:5,request:[4,5,2],doe:[6,7,5,2],declar:7,determin:[1,2,3,5,6,7],occasion:6,sum:[0,1,3],"0x00b8fb18":[],parser_bar:2,show:[6,0,7,5,2],text:6,filetyp:[8,0,4,5],syntax:[8,7,1],particularli:[7,6,2],hack:7,find:[3,1,2],onli:[6,7,1,2,5],parse_known_arg:2,execut:2,pretti:3,"true":[1,2,3,5,6,7],parser_foo:2,written:0,should:[0,2,3,5,6,7],store_const:[3,7,1,5],wood:1,dict:5,"__call__":[7,5],add_opt:7,variou:[5,6],get:[6,3,7,1,2],express:6,report:5,requir:[8,7,1,2,5],bar:[1,2,3,5,6,7],keyword:[1,2,3,5,6,7],baz:[7,5,2],dramat:7,yield:2,patch:7,store_fals:[5,2],"default":[0,1,2,3,5,6,7,8],bad:[1,5],calcul:6,common:[3,5,6],contain:[1,2,5,6,7,8],where:[0,5,6],set:[6,3,7,5,2],see:[1,2,3,5,6,7],arg:[0,1,2,3,4,5,6,7],close:0,parent:[8,7,6,2],correctli:6,someth:3,figur:5,subdir:6,between:6,"import":[0,7,5,6,3],awai:5,badger:[7,1,2],across:6,attribut:[1,2,3,5,6,7],altern:6,extend:[7,5],xrang:[3,7,1,5],disallow:[7,6],extens:7,outfil:5,come:7,addit:[6,7,5,2],both:[7,1],last:[1,6],howev:[6,7,5,2],against:7,etc:[7,1,2,5],mani:[7,5],whole:[],simpli:[6,7,1,2,5],point:7,within:6,argumentpars:[0,1,2,3,4,5,6,7,8],dispatch:7,suppli:[6,3,7,5,2],respect:5,assum:[0,5,2,3],duplic:7,quit:[7,5],coupl:[6,2],addition:5,three:6,empti:1,implicit:7,accumul:[3,1],secret:7,much:[3,7,1,2,5],valu:[1,2,5,6,7,8],basic:5,unambigu:1,print_usag:2,popul:[1,2],strategi:6,epilog:[8,6],suppress:[7,5,6],xxx:[7,5,6],great:5,ani:[6,7,5,2],understand:4,togeth:[1,5],func:2,child:6,repetit:5,present:[7,1,2,5],"case":[3,1,2,5],therefor:5,look:[3,7,1],format_help:2,formatt:6,defin:[6,5,2],invok:[6,3,7,5,2],abov:[6,0,1,2,3],error:[6,7,1,2,5],argpars:[0,1,2,3,4,5,6,7],advantag:[0,7],stdout:[0,4,5],readi:3,itself:5,arg_lin:2,sever:[6,1,2],disabl:6,clearli:1,perform:[5,2],make:[6,3,7,5,2],transpar:7,same:[7,5,6],handl:[7,5,2],complex:[7,5],help_:[],split:[1,2,3,5,6,7],document:[8,0,1],infer:5,dest_:[],difficult:7,dedent:6,foo_bar_baz_pars:7,effect:2,rais:[5,6],user:[6,7,1,2,5],store_act:7,typic:[3,7,5,2],recent:6,appropri:[0,2,3,5,6,7],older:6,argumenttypeerror:5,thu:7,inherit:[7,6],likewis:6,exampl:[0,1,2,3,5,6],command:[0,1,2,3,4,5,6,7,8],thi:[0,1,2,3,4,5,6,7],conflict:6,everyth:[7,1],sibl:2,usual:[6,7,5,2],identifi:5,just:[5,2],object:[0,1,2,3,4,5,6,7,8],add_mutually_exclusive_group:2,note:[6,7,5,2],action_:[],exclus:[8,2],expos:7,had:7,except:[6,2],add:[0,2,3,5,6,7],other:[0,1,2,4,6,7,8],remaining_arg:7,rawdescriptionhelpformatt:6,save:[0,3],match:[6,7,1,2,5],applic:[6,2],format:[6,7,5,2],dest:[1,2,3,5,7,8],textwrap:6,test:7,built:[3,1],know:[7,5,2],get_default:2,insert:1,like:[1,2,3,5,6,7],specif:6,arbitrari:5,whitespac:6,manual:7,resolv:6,integ:[0,5,7,1,3],collect:6,necessari:[3,7,5,2],either:[1,2,3,5,6,7],argumenterror:[7,6],output:[6,4,5,2],unnecessari:6,encount:[3,1,5],old:[6,2],often:5,"0x00b1f020":[],interact:1,some:[1,2,3,5,6,7],back:2,intern:5,suppl:2,mistak:1,proper:7,librari:7,subpars:[7,2],avoid:5,normal:[1,2,5],definit:6,subclass:2,exit:[0,1,2,5,6,7],parent_pars:6,foo:[1,2,3,5,6,7],refer:[1,6,5],nargs_:[],print_help:[6,7,5,2],run:[0,3],inspect:[3,2],usag:[0,1,2,5,6,7,8],argument_default:[8,6],found:1,add_subpars:[7,2],"__name__":[0,3],"super":7,xyzz:1,about:[6,3,7,5,2],simplest:1,actual:7,meth:[],callback_:7,optpars:[0,7],constructor:[7,6,2],commit:2,produc:[7,5,2],own:[6,7,5,2],xyz:[7,2],"float":[7,5,2],automat:[4,5,6],upgrad:[0,7],been:[3,7,5],strip:[5,2],wrap:6,chang:[6,7,5,2],mark:5,yyi:[5,6],your:[6,3,7,5,2],manag:3,inclus:5,log:0,wai:[6,7,1,2,5],spam:[7,1,2],support:[6,7,1,2,5],textual:6,custom:[6,8,1,2,5],avail:[6,5,2],start:[3,6],interfac:[0,7,5,3],includ:[6,7,1,2,5],lot:[7,2],parse_arg:[0,1,2,3,4,5,6,7,8],treat:[6,2],"function":[1,2,5],svn:2,creation:[6,2],form:[3,7,5],tupl:[5,2],bufsiz:[4,5],continu:2,msg:5,parents_:[],"0x00b8fe78":[],eas:5,conflict_handl:[8,6],absent:5,made:1,input:5,temp:5,possibl:5,whether:[5,6],checkout:2,argumentdefaultshelpformatt:6,displai:[6,7,5,2],below:[7,5,6],otherwis:6,similar:7,featur:7,constant:5,creat:[0,1,2,3,4,5,6,7],"int":[0,1,2,3,5,6,7],pseudo:[4,1],parser:[0,1,2,3,4,5,6,7,8],"0x00b1f068":[],doesn:[7,5],strongli:2,exist:1,file:[0,2,3,4,5,6,7,8],xyzyx:2,check:[7,1,2,5],fill:[3,6],again:7,mutual:[8,2],titl:2,when:[0,1,2,3,5,6,7],detail:[1,6,5],invalid:[8,7,1,5],valid:[7,5,2],futur:2,scriptnam:0,varieti:1,writabl:[4,5],set_default:[6,2],you:[1,2,3,5,6,7],bar_pars:[7,6],repeat:6,clean:6,why:7,consid:[5,6],"0x00adf020":[],reduc:7,receiv:7,longer:[7,1,2],descript:[0,2,3,5,6,8],time:[7,5,2],backward:7,convert_arg_line_to_arg:[6,2]},titles:["Documentation","The parse_args() method","Other methods","Introduction to argparse","Other utilities","The add_argument() method","ArgumentParser objects","argparse vs. optparse","API documentation"],modules:{},descrefs:{"":{parse_args:[1,0],parse_known_args:[2,0],add_mutually_exclusive_group:[2,0],set_defaults:[2,0],FileType:[4,1],add_argument:[5,0],ArgumentParser:[6,1],convert_arg_line_to_args:[2,0],add_argument_group:[2,0],add_subparsers:[2,0],get_default:[2,0]}},filenames:["index","parse_args","other-methods","overview","other-utilities","add_argument","ArgumentParser","argparse-vs-optparse","api-docs"]}) \ No newline at end of file diff --git a/doc/source/ArgumentParser.rst b/doc/source/ArgumentParser.rst index f50ab5d..58f37cc 100644 --- a/doc/source/ArgumentParser.rst +++ b/doc/source/ArgumentParser.rst @@ -1,13 +1,12 @@ ArgumentParser objects ====================== -.. class:: ArgumentParser([description], [epilog], [prog], [usage], [version], [add_help], [argument_default], [parents], [prefix_chars], [conflict_handler], [formatter_class]) +.. class:: ArgumentParser([description], [epilog], [prog], [usage], [add_help], [argument_default], [parents], [prefix_chars], [conflict_handler], [formatter_class]) Create a new :class:`ArgumentParser` object. Each parameter has its own more detailed description below, but in short they are: * description_ - Text to display before the argument help. * epilog_ - Text to display after the argument help. - * version_ - A version number used to add a -v/--version option to the parser. * add_help_ - Add a -h/--help option to the parser. (default: True) * argument_default_ - Set the global default value for arguments. (default: None) * parents_ - A list of :class:ArgumentParser objects whose arguments should also be included. @@ -59,24 +58,6 @@ Some programs like to display additional description of the program after the de As with the description_ argument, the ``epilog=`` text is by default line-wrapped, but this behavior can be adjusted with the formatter_class_ argument to ArgumentParser. -version -------- - -Programs which want to display the program version at the command line can supply a version message as the ``version=`` argument to ArgumentParser. This will add a ``-v/--version`` option to the ArgumentParser that can be invoked to print the version string:: - - >>> parser = argparse.ArgumentParser(prog='PROG', version='%(prog)s 3.5') - >>> parser.print_help() - usage: PROG [-h] [-v] - - optional arguments: - -h, --help show this help message and exit - -v, --version show program's version number and exit - >>> parser.parse_args(['-v']) - PROG 3.5 - -Note you can use the ``%(prog)s`` format specifier to insert the program name into the version string. For greater customization, see the documentation on the ``'version'`` action available for :meth:`add_argument`. - - add_help -------- diff --git a/doc/source/add_argument.rst b/doc/source/add_argument.rst index e72df5b..374d742 100644 --- a/doc/source/add_argument.rst +++ b/doc/source/add_argument.rst @@ -85,12 +85,12 @@ action >>> parser.parse_args('--str --int'.split()) Namespace(types=[, ]) -* ``'version'`` - This expects a ``version=`` keyword argument in the :meth:`add_argument` call, and prints version information and exits when invoked. This can be used when the default :class:`ArgumentParser` version flags ``-v, --version`` are not appropriate for your program. +* ``'version'`` - This expects a ``version=`` keyword argument in the :meth:`add_argument` call, and prints version information and exits when invoked. >>> import argparse >>> parser = argparse.ArgumentParser(prog='PROG') - >>> parser.add_argument('-V', action='version', version='%(prog)s 2.0') - >>> parser.parse_args(['-V']) + >>> parser.add_argument('-v', '--version', action='version', version='%(prog)s 2.0') + >>> parser.parse_args(['-v']) PROG 2.0 You can also specify an arbitrary action by passing an object that implements the Action API. The easiest way to do this is to extend ``argparse.Action``, supplying an appropriate ``__call__`` method. The ``__call__`` method accepts four parameters: -- cgit v1.2.1