Import argparseusage = "" "%prog-q phylogroup-o Out_file, you shall provide the phyloname of query" "" parser = Argparse. Argumentparser (description = USAGE) parser.add_argument ('-O ', '--output ', default = ' Test_result.txt ') parser.add_ Argument ("-Q", "--query", default = "CD12") args = Parser.parse_args () print Args.outputprint args.query
In this example, two option parameters--------------------and-Q are accepted, and the default
If you want to add an option that does not accept parameter passing.
Then use the following methods
Parser.add_argument ('-a ', action= "Store_true", Default=false) parser.add_argument ('-t ', '--tcp ', help= ' TCP service ', action= ' Store_true ')
If you want to change the data type of a parameter, the default is a string, or it can be set to int or float
Parser.add_argument ('-P ',--Port ', Type=int, help= "use a number as port") parser.add_argument ("Square", help= "display a Square of a given number ", Type=int)
In fact, the simplest notation is
Parser.add_argument (' Bar ') parser.add_argument ("echo") args = Parser.parse_args () # # accesses the parameters passed to bar and Echo, using the following method: Print Args.barprint Args.echo
For example, the following is saved to the 12.py file:
#!/usr/bin/env python#-*-coding:utf-8-*-import argparseusage = ""%prog-q phylogroup-o Out_file, you shall provide The Phyloname of query "" "parser = Argparse. Argumentparser (description = USAGE) parser.add_argument ("Bar") parser.add_argument ("echo") args = Parser.parse_args () Print Args.echoprint args.bar## The string that corresponds to the output parameter is in sequence.
The results of the implementation are as follows:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/83/49/wKiom1dvbLKAeoqIAAB1BoRUNF8119.jpg-wh_500x0-wm_3 -wmp_4-s_3726590244.jpg "title=" poo. JPG "alt=" Wkiom1dvblkaeoqiaab1borunf8119.jpg-wh_50 "/>
Python's argparse module processing parameters