python:argparse

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
次のリビジョン両方とも次のリビジョン
python:argparse [2020/02/01 19:49] – [参考文献] ともやんpython:argparse [2020/02/01 19:55] – [実行例] ともやん
行 10: 行 10:
     parser = argparse.ArgumentParser()     parser = argparse.ArgumentParser()
     parser.add_argument('target_dir', help='target dir.', type=str)     parser.add_argument('target_dir', help='target dir.', type=str)
-    parser.add_argument('--exclude', help='exclude directory or file.', type=str)+    parser.add_argument('--exclude', nargs='+', help='exclude directory or file.', type=str)
     return parser.parse_args()     return parser.parse_args()
  
行 29: 行 29:
 <code> <code>
 $ python args_sample.py $ python args_sample.py
-usage: args_sample.py [-h] [--exclude EXCLUDE] target_dir+usage: args_sample.py [-h] [--exclude EXCLUDE [EXCLUDE ...]] target_dir
 args_sample.py: error: the following arguments are required: target_dir args_sample.py: error: the following arguments are required: target_dir
  
 $ python args_sample.py -h $ python args_sample.py -h
-usage: args_sample.py [-h] [--exclude EXCLUDE] target_dir+usage: args_sample.py [-h] [--exclude EXCLUDE [EXCLUDE ...]] target_dir
  
 positional arguments: positional arguments:
-  target_dir         target dir.+  target_dir            target dir.
  
 optional arguments: optional arguments:
-  -h, --help         show this help message and exit +  -h, --help            show this help message and exit 
-  --exclude EXCLUDE  exclude directory or file.+  --exclude EXCLUDE [EXCLUDE ...] 
 +                        exclude directory or file.
  
 </code> </code>
  • python/argparse.txt
  • 最終更新: 2020/09/11 16:30
  • by ともやん