python:argparse

差分

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

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
最新のリビジョン両方とも次のリビジョン
python:argparse [2020/02/01 20:04] – [実行例] ともやんpython:argparse [2020/05/31 01:30] ともやん
行 1: 行 1:
-====== argparse ======+<html> 
 +  <style> 
 +    #result pre, #mincode pre { 
 +      overflow: hidden; 
 +      font-size: 10px; 
 +    } 
 +    #result_long pre { 
 +      height: 250px; 
 +      overflow: scroll; 
 +      overflow-x: hidden; 
 +      font-size: 10px; 
 +    } 
 +    #mintbl table { 
 +      font-size: 12px; 
 +    } 
 +    #mintbl td pre { 
 +      margin: 0; 
 +    } 
 +    #img_long { 
 +      height: 400px; 
 +      overflow: scroll; 
 +      overflow-x: hidden; 
 +    } 
 +    .dokuwiki .plugin_wrap table { 
 +      width: auto; 
 +    } 
 +    #logo { 
 +      background-color: white; 
 +      padding: 10px; 
 +      width: fit-content; 
 +    } 
 +    #logo p { 
 +      margin: 0; 
 +    } 
 +  </style> 
 +</html> 
 +====== argparse - コマンドライン引数解析 ======
  
 ===== サンプル ===== ===== サンプル =====
 +<WRAP prewrap 100% #mincode>
 <code python args_sample.py> <code python args_sample.py>
 #!/usr/bin/env python #!/usr/bin/env python
行 24: 行 61:
     main()     main()
 </code> </code>
 +</WRAP>
  
 ===== 実行例 ===== ===== 実行例 =====
-<code>+<WRAP prewrap 100%> 
 +<code powershell>
 $ python args_sample.py $ python args_sample.py
 +</code>
 +</WRAP>
 +<WRAP prewrap 100% #result>
 +<code powershell>
 usage: args_sample.py [-h] [--exclude 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
 +</code>
 +</WRAP>
  
 +<WRAP prewrap 100%>
 +<code powershell>
 $ python args_sample.py -h $ python args_sample.py -h
 +</code>
 +</WRAP>
 +<WRAP prewrap 100% #result>
 +<code powershell>
 usage: args_sample.py [-h] [--exclude EXCLUDE [EXCLUDE ...]] target_dir usage: args_sample.py [-h] [--exclude EXCLUDE [EXCLUDE ...]] target_dir
  
行 41: 行 92:
   --exclude EXCLUDE [EXCLUDE ...]   --exclude EXCLUDE [EXCLUDE ...]
                         exclude directory or file.                         exclude directory or file.
 +</code>
 +</WRAP>
  
 +<WRAP prewrap 100%>
 +<code powershell>
 $ python args_sample.py / --exclude .git $ python args_sample.py / --exclude .git
 +</code>
 +</WRAP>
 +<WRAP prewrap 100% #result>
 +<code powershell>
 target_dir: / target_dir: /
 exclude_dirs: ['.git'] exclude_dirs: ['.git']
- 
 </code> </code>
 +</WRAP>
  
 ===== 参考文献 ===== ===== 参考文献 =====
  • python/argparse.txt
  • 最終更新: 2020/09/11 16:30
  • by ともやん