File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed
source-code/command-line-arguments/ArgParse Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,12 @@ $ ./generate_gaussian.py -h
14141 . ` partial_parse.py ` : illustrate how to parse only known arguments.
15151 . ` two_stage_parse.py ` : parsing input from a file as if it were command
1616 line arguments (using ` shlex ` ) and merging with command line arguments.
17- ``` bash
18- $ ./two_stage_parse.py -l mem=8gb -I job_script.pbs -k oe
19- ```
20- ` . ` job_script.pbs` : file to use with ` two_stage_parse.py`.
17+ ``` bash
18+ $ ./two_stage_parse.py -l mem=8gb -I job_script.pbs -k oe
19+ ```
20+ 1 . ` job_script.pbs ` : file to use with ` two_stage_parse.py ` .
21+ 1 . ` options_in_file.py ` : illustration of how to read options from a file.
22+ ``` bash
23+ ./options_in_file.py --foo something @file_options.txt
24+ ```
25+ 1 . ` file_options.txt ` : file containing options for ` options_in_file.py ` .
Original file line number Diff line number Diff line change 1+ --foo
2+ This is the foo value
3+ --flag
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ import argparse
4+
5+
6+ def amin ():
7+ arg_parser = argparse .ArgumentParser (fromfile_prefix_chars = '@' )
8+ arg_parser .add_argument ('--foo' , help = 'foo option' )
9+ arg_parser .add_argument ('--bar' , help = 'bar optoin' )
10+ arg_parser .add_argument ('--flag' , action = 'store_true' ,
11+ help = 'flag option' )
12+ options = arg_parser .parse_args ()
13+ print (options )
14+
15+ if __name__ == '__main__' :
16+ amin ()
You can’t perform that action at this time.
0 commit comments