<small id='yTHSA'></small><noframes id='yTHSA'>

    <tfoot id='yTHSA'></tfoot>
  • <legend id='yTHSA'><style id='yTHSA'><dir id='yTHSA'><q id='yTHSA'></q></dir></style></legend>

    1. <i id='yTHSA'><tr id='yTHSA'><dt id='yTHSA'><q id='yTHSA'><span id='yTHSA'><b id='yTHSA'><form id='yTHSA'><ins id='yTHSA'></ins><ul id='yTHSA'></ul><sub id='yTHSA'></sub></form><legend id='yTHSA'></legend><bdo id='yTHSA'><pre id='yTHSA'><center id='yTHSA'></center></pre></bdo></b><th id='yTHSA'></th></span></q></dt></tr></i><div id='yTHSA'><tfoot id='yTHSA'></tfoot><dl id='yTHSA'><fieldset id='yTHSA'></fieldset></dl></div>
          <bdo id='yTHSA'></bdo><ul id='yTHSA'></ul>

        Python:argparse subcommand 子命令?

        Python: argparse subcommand subcommand?(Python:argparse subcommand 子命令?)
        • <legend id='MLGQM'><style id='MLGQM'><dir id='MLGQM'><q id='MLGQM'></q></dir></style></legend>
          <tfoot id='MLGQM'></tfoot>

          <small id='MLGQM'></small><noframes id='MLGQM'>

          • <i id='MLGQM'><tr id='MLGQM'><dt id='MLGQM'><q id='MLGQM'><span id='MLGQM'><b id='MLGQM'><form id='MLGQM'><ins id='MLGQM'></ins><ul id='MLGQM'></ul><sub id='MLGQM'></sub></form><legend id='MLGQM'></legend><bdo id='MLGQM'><pre id='MLGQM'><center id='MLGQM'></center></pre></bdo></b><th id='MLGQM'></th></span></q></dt></tr></i><div id='MLGQM'><tfoot id='MLGQM'></tfoot><dl id='MLGQM'><fieldset id='MLGQM'></fieldset></dl></div>
            • <bdo id='MLGQM'></bdo><ul id='MLGQM'></ul>

                    <tbody id='MLGQM'></tbody>
                  本文介绍了Python:argparse subcommand 子命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的程序有很多可用选项.例如用于更改设置的配置选项.

                  I have a program that has many available options. For example a configuration option to change settings.

                  ./app config -h
                  

                  使用普通的 argparse 子命令帮助我

                  gives me the help using normal argparse subcommands

                  现在我想在名为 list 的配置子命令中添加另一个子命令以列出配置值

                  now i would like to add another subcommand to the config subcommand called list to list config values

                  ./app config list
                  

                  此外,该命令应该接受另一个选项,以便我可以说

                  additionally that command should accept another option so that i could say

                  ./app config list CATEGORY
                  

                  只列出一个类别的配置

                  我现在的代码基本上就是这样,只是有更多的命令

                  my code right now is basically this just with more commands

                  >>> parser = argparse.ArgumentParser()
                  >>> subparsers = parser.add_subparsers(title='subcommands',
                  ...                                    description='valid subcommands',
                  ...                                    help='additional help')
                  >>> subparsers.add_parser('foo')
                  >>> subparsers.add_parser('bar')
                  >>> parser.parse_args(['-h'])
                  usage:  [-h] {foo,bar} ...
                  
                  optional arguments:
                    -h, --help  show this help message and exit
                  
                  subcommands:
                    valid subcommands
                  
                    {foo,bar}   additional help
                  

                  到目前为止,我找不到在子命令中使用子命令的任何方法.如果这是可能的,怎么做?如果没有,还有其他方法可以实现这个目标吗?

                  So far I could not find any way to use a subcommand in a subcommand. If this is possible, how? If not, is there any other way to accomplish this goal?

                  提前致谢

                  推荐答案

                  #file: argp.py
                  
                  import argparse
                  
                  parser = argparse.ArgumentParser(prog='PROG')
                  parser_subparsers = parser.add_subparsers()
                  sub = parser_subparsers.add_parser('sub')
                  sub_subparsers = sub.add_subparsers()
                  sub_sub = sub_subparsers.add_parser('sub_sub')                                                                       
                  sub_sub_subparsers = sub_sub.add_subparsers()
                  sub_sub_sub = sub_sub_subparsers.add_parser('sub_sub_sub')
                  

                  似乎有效.

                  In [392]: run argp.py
                  
                  In [393]: parser.parse_args('sub sub_sub sub_sub_sub'.split())
                  Out[393]: Namespace()
                  
                  In [400]: sys.version_info
                  Out[400]: sys.version_info(major=2, minor=7, micro=2, releaselevel='final', serial=0)
                  

                  这篇关于Python:argparse subcommand 子命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                  <tfoot id='NTS3w'></tfoot>
                  1. <small id='NTS3w'></small><noframes id='NTS3w'>

                    • <legend id='NTS3w'><style id='NTS3w'><dir id='NTS3w'><q id='NTS3w'></q></dir></style></legend>

                        <i id='NTS3w'><tr id='NTS3w'><dt id='NTS3w'><q id='NTS3w'><span id='NTS3w'><b id='NTS3w'><form id='NTS3w'><ins id='NTS3w'></ins><ul id='NTS3w'></ul><sub id='NTS3w'></sub></form><legend id='NTS3w'></legend><bdo id='NTS3w'><pre id='NTS3w'><center id='NTS3w'></center></pre></bdo></b><th id='NTS3w'></th></span></q></dt></tr></i><div id='NTS3w'><tfoot id='NTS3w'></tfoot><dl id='NTS3w'><fieldset id='NTS3w'></fieldset></dl></div>
                          <bdo id='NTS3w'></bdo><ul id='NTS3w'></ul>
                              <tbody id='NTS3w'></tbody>