Note that there are some explanatory texts on larger screens.

plurals
  1. POAppending to a tuple overwriting previous values
    primarykey
    data
    text
    <p>I'm using arcpy to get all the polylines of a shape file. <code>SearchCursor</code> 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. </p> <pre><code>import arcpy from arcpy import env env.workspace = r"C:\GIS Data\GIS 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 </code></pre> <p>Tuple supposed to contain all the objects returned by cursor. But it has only the last elements repeated <code>size</code> of tuple number of times.</p> <blockquote> <p>3610930 2135882 3611593 2134453</p> <p>3611806 2134981 3611593 2134453</p> <p>3614160 2136164 3617432 2131734</p> <p>3611593 2134453 3617432 2131734</p> <p>3617432 2131734 3620568 2127591</p> <p>3620568 2127591 3620785 2127423</p> <p>3617980 2126657 3620568 2127591</p> <p>3616768 2129454 3617948 2126649</p> <p>3617948 2126649 3617980 2126657</p> <p>3615102 2128889 3617587 2126510</p> <p>3617587 2126510 3617948 2126649</p> <p>3617624 2126416 3617980 2126657</p> <p>3613129 2128176 3615155 2125617</p> <p>3615155 2125617 3617587 2126510</p> <p>3615086 2125515 3615155 2125617</p> <hr> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> <p>3615086 2125515 3615155 2125617</p> </blockquote> <p>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 <code>+</code> overwrites all the previous elements of tuple. Although this code is written for arcpy, but I guess the problem isn't arcgis specific.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload