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

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

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

    <tfoot id='Yd4FW'></tfoot>

        <bdo id='Yd4FW'></bdo><ul id='Yd4FW'></ul>

      附加到覆盖先前值的元组

      Appending to a tuple overwriting previous values(附加到覆盖先前值的元组)
        <tbody id='qmmhj'></tbody>
      • <bdo id='qmmhj'></bdo><ul id='qmmhj'></ul>

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

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

            <legend id='qmmhj'><style id='qmmhj'><dir id='qmmhj'><q id='qmmhj'></q></dir></style></legend>
              • <tfoot id='qmmhj'></tfoot>
                本文介绍了附加到覆盖先前值的元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 arcpy 来获取形状文件的所有折线.SearchCursor 返回一个光标,以便我可以遍历形状文件的所有功能.问题是我想保存游标返回的所有对象以供以后使用.

                I'm using arcpy to get all the polylines of a shape file. SearchCursor returns a cursor so that I can iterate over all the features of shape file. Problem is I want to save all the objects returned by cursor for later use.

                import arcpy
                from arcpy import env
                
                env.workspace = r"C:GIS DataGIS data"
                
                desc = arcpy.Describe("River.shp")
                shapefieldname = desc.ShapeFieldName
                
                rows = arcpy.SearchCursor("River.shp")
                
                featureList = ()
                
                for row in rows:
                    feat = row.getValue(shapefieldname)
                
                    featureList = featureList + (feat, )
                
                    print "%i %i" % (featureList[-1].firstPoint.X, featureList[-1].firstPoint.Y)
                    print "%i %i" % (featureList[-1].lastPoint.X, featureList[-1].lastPoint.Y)
                
                    print
                
                print "---------------------------------------------------------------"
                
                for feat in featureList:
                    print "%i %i" % (feat.firstPoint.X, feat.firstPoint.Y)
                    print "%i %i" % (feat.lastPoint.X, feat.lastPoint.Y)
                    print
                

                元组应该包含游标返回的所有对象.但它只有最后一个元素重复 size 元组次数.

                Tuple supposed to contain all the objects returned by cursor. But it has only the last elements repeated size of tuple number of times.

                3610930 2135882 3611593 2134453

                3610930 2135882 3611593 2134453

                3611806 2134981 3611593 2134453

                3611806 2134981 3611593 2134453

                3614160 2136164 3617432 2131734

                3614160 2136164 3617432 2131734

                3611593 2134453 3617432 2131734

                3611593 2134453 3617432 2131734

                3617432 2131734 3620568 2127591

                3617432 2131734 3620568 2127591

                3620568 2127591 3620785 2127423

                3620568 2127591 3620785 2127423

                3617980 2126657 3620568 2127591

                3617980 2126657 3620568 2127591

                3616768 2129454 3617948 2126649

                3616768 2129454 3617948 2126649

                3617948 2126649 3617980 2126657

                3617948 2126649 3617980 2126657

                3615102 2128889 3617587 2126510

                3615102 2128889 3617587 2126510

                3617587 2126510 3617948 2126649

                3617587 2126510 3617948 2126649

                3617624 2126416 3617980 2126657

                3617624 2126416 3617980 2126657

                3613129 2128176 3615155 2125617

                3613129 2128176 3615155 2125617

                3615155 2125617 3617587 2126510

                3615155 2125617 3617587 2126510

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                3615086 2125515 3615155 2125617

                起初,我尝试过使用列表.当我使用append()"方法时,也为列表找到了相同的输出.由于 tuple 是不可变的数据结构,+ 怎么会覆盖 tuple 之前的所有元素呢?虽然这段代码是为 arcpy 编写的,但我猜问题不是 arcgis 特有的.

                At first, I've tried this using list. Same output was also found for list when I've used 'append()' method. As tuple is immutable data structure, how can + overwrites all the previous elements of tuple. Although this code is written for arcpy, but I guess the problem isn't arcgis specific.

                推荐答案

                这表明 row.getValue() 不断返回对同一对象的引用 ,这它会不断更新.

                What this suggests is that row.getValue() keeps returning references to the same object, which it keeps updating in place.

                要验证,请尝试在第一个打印 id(feat)id(feat.firstPoint)id(feat.lastPoint)循环,并查看迭代之间是否有任何 id 保持不变.如果他们中的任何一个这样做,那是你的问题.

                To verify, try printing id(feat), id(feat.firstPoint) and id(feat.lastPoint) in the first loop, and see whether any of the ids remain the same between iterations. If any of them do, that's your problem.

                由于元组是不可变的数据结构,如何 + 覆盖元组之前的所有元素.

                As tuple is immutable data structure, how can + overwrites all the previous elements of tuple.

                它没有.元组是不可变的,因为您不能在不创建新元组的情况下添加或删除元素.您也不能更改元组元素的值.但是,如果该元素是对可变对象的引用,您可以自由修改对象本身.这就是我怀疑这里发生的事情:您对同一个对象有多个引用;当您修改一个时,它们似乎都发生了变化.

                It doesn't. Tuple is immutable in the sense that you can't add or remove elements from it without creating a new tuple. You also can't change the value of a tuple element. However, if that element is a reference to a mutable object, you are free to modify the object itself. This is what I suspect is happening here: you have multiple references to the same object; when you modify one, they all appear to change.

                这篇关于附加到覆盖先前值的元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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='TOGEc'></bdo><ul id='TOGEc'></ul>
                        <tfoot id='TOGEc'></tfoot>

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

                        1. <legend id='TOGEc'><style id='TOGEc'><dir id='TOGEc'><q id='TOGEc'></q></dir></style></legend>

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