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

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

        • <bdo id='xSi07'></bdo><ul id='xSi07'></ul>
      1. <tfoot id='xSi07'></tfoot>

        提供可变数量参数的python函数

        Feed python function with a variable number of arguments(提供可变数量参数的python函数)

          <tfoot id='RJZM1'></tfoot>

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

            <tbody id='RJZM1'></tbody>
            • <bdo id='RJZM1'></bdo><ul id='RJZM1'></ul>

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

                  <legend id='RJZM1'><style id='RJZM1'><dir id='RJZM1'><q id='RJZM1'></q></dir></style></legend>
                1. 本文介绍了提供可变数量参数的python函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个脚本,它从输入文件中读取可变数量的字段并将它们作为参数传递给函数.例如:

                  I have a script that reads a variable number of fields from an input file and pass them to a function as arguments. For example:

                  文件 1 包含字段:A、B 和 C => function(A,B,C)

                  file 1 with fields: A,B and C => function(A,B,C)

                  文件 N 包含字段:A,B,C 和 D => function(A,B,C,D)

                  file N with fields: A,B,C and D => function(A,B,C,D)

                  我的问题是:如何根据输入文件为函数提供正确数量的字段?

                  My question is: How to feed the function with the right number of fields accordingly to the input file?.

                  PD:当然函数接受任意数量的参数

                  PD: Of course the function accepts any number of arguments

                  推荐答案

                  将字段(参数)读入列表,然后使用 参数解包:

                  Read the fields (arguments) into a list and then use argument unpacking:

                  function(*fields)
                  

                  下面是一个演示:

                  >>> def func(*args):
                  ...     return args
                  ...
                  >>> fields = ["A", "B", "C"]
                  >>> func(*fields)
                  ('A', 'B', 'C')
                  >>> fields = ["A", "B", "C", "D"]
                  >>> func(*fields)
                  ('A', 'B', 'C', 'D')
                  >>>
                  

                  这篇关于提供可变数量参数的python函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)

                        • <bdo id='tvFFP'></bdo><ul id='tvFFP'></ul>

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

                              <tbody id='tvFFP'></tbody>
                          2. <legend id='tvFFP'><style id='tvFFP'><dir id='tvFFP'><q id='tvFFP'></q></dir></style></legend>

                            <tfoot id='tvFFP'></tfoot>
                          3. <small id='tvFFP'></small><noframes id='tvFFP'>