<tfoot id='m800j'></tfoot>

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

      <legend id='m800j'><style id='m800j'><dir id='m800j'><q id='m800j'></q></dir></style></legend>

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

        Python struct.pack() 用于列表中的单个元素?

        Python struct.pack() for individual elements in a list?(Python struct.pack() 用于列表中的单个元素?)
      1. <tfoot id='oQ3V0'></tfoot>

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

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

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

                  本文介绍了Python struct.pack() 用于列表中的单个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想将列表中的所有数据打包到一个缓冲区中,以通过 UDP 套接字发送.该列表相对较长,因此为列表中的每个元素编制索引很繁琐.这是我目前所拥有的:

                  I would like to pack all the data in a list into a single buffer to send over a UDP socket. The list is relatively long, so indexing each element in the list is tedious. This is what I have so far:

                  NumElements = len(data)
                  buf = struct.pack('d'*NumElements,data[0],data[1],data[2],data[3],data[4])
                  

                  但是如果我向列表中添加更多元素,我想做一些不需要更改调用的更 Pythonic 的东西......类似于:

                  But I would like to do something more pythonic that doesn't require I change the call if I added more elements to the list... something like:

                  NumElements = len(data)
                  buf = struct.pack('d'*NumElements,data)  # Returns error
                  

                  有什么好的方法吗??

                  推荐答案

                  是的,你可以使用 *args 调用语法.

                  Yes, you can use the *args calling syntax.

                  而不是这个:

                  buf = struct.pack('d'*NumElements,data)  # Returns error
                  

                  ……这样做:

                  buf = struct.pack('d'*NumElements, *data) # Works
                  

                  请参阅教程中的解包参数列表.(但实际上,请阅读第 4.7 节的所有内容,而不仅仅是 4.7.4,否则您将不知道相反的情况……"指的是什么……)简要:

                  See Unpacking Argument Lists in the tutorial. (But really, read all of section 4.7, not just 4.7.4, or you won't know what "The reverse situation…" is referring to…) Briefly:

                  ...当参数已经在列表或元组中但需要为需要单独的位置参数的函数调用解包时...使用 *-operator 编写函数调用以将参数从列表或元组中解包...

                  … when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arguments… write the function call with the *-operator to unpack the arguments out of a list or tuple…

                  这篇关于Python struct.pack() 用于列表中的单个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

                  1. <small id='NciVv'></small><noframes id='NciVv'>

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

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