<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python script that will create a list of a shapefiles values in a field. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71951#M5927</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I see now.&amp;nbsp; Glad you got it working!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Apr 2013 22:29:33 GMT</pubDate>
    <dc:creator>MikeHunter</dc:creator>
    <dc:date>2013-04-30T22:29:33Z</dc:date>
    <item>
      <title>Python script that will create a list of a shapefiles values in a field.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71947#M5923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been searching around these forums for awhile now trying to track something down that could help me solve the problem that I am having. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically I have 800~ rasters that I can get an output for in the correct order in a list. I need to then take these 800 rasters and multiply each one by a value in a shapefiles attribute table under the field Sum_Count.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was able to get a printed list of the values that I wanted by using a SearchCursor and a rows.next() function. The issue is that this was only printing out the values for me and not creating a list from these values that I can then use in a calculation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code is very sloppy right now as I am VERY new with python so I apologize. My boss just asked me to help him with this and I have been going off things I have found on the internet. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os from arcpy import env from arcpy.sa import *&amp;nbsp; arcpy.CheckOutExtension("Spatial")&amp;nbsp; env.workspace = r"E:\Models_Ken\PSI_Outputs\Test_Small_Run"&amp;nbsp; list1 = []&amp;nbsp; lstRasters = arcpy.ListRasters("*") for raster in lstRasters: &amp;nbsp;&amp;nbsp;&amp;nbsp; list1.append(env.workspace + os.sep + raster) &amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Successfully created list1' &amp;nbsp;&amp;nbsp;&amp;nbsp; print list1&amp;nbsp; #env.workspace = r"E:\Models_Ken\PSI_Outputs\Test_Small_Run"&amp;nbsp; featureClass = r"E:\Models_Ken\PSI_Outputs\Test_Small_Run\Tract_Centroids_Test.shp"&amp;nbsp; list2 = []&amp;nbsp; #fclist = arcpy.ListFeatureClasses("*","Point") #for fc in fclist: &amp;nbsp;&amp;nbsp;&amp;nbsp; #list2.append(env.workspace + os.sep + raster) &amp;nbsp;&amp;nbsp;&amp;nbsp; #print 'Successfully created list2'&amp;nbsp; rows = arcpy.SearchCursor(featureClass) row = rows.next() while row: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.Sum_Count &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()&amp;nbsp;&amp;nbsp; count = len(list1)&amp;nbsp; x = 0 while x &amp;lt; count: &amp;nbsp;&amp;nbsp;&amp;nbsp; raster = list1&lt;X&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; name = raster.split("\\")[-1] &amp;nbsp;&amp;nbsp;&amp;nbsp; inParcelNumber = row.Sum_Count &amp;nbsp;&amp;nbsp;&amp;nbsp; outTimes = raster * inParcelNumber &amp;nbsp;&amp;nbsp;&amp;nbsp; outTimes.save(r"E:\Models_Ken\PSI_Outputs\Test_Small_Run_Output" + os.sep + name.split(".")[0] + "_minus.tif") &amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Successfully created raster' &amp;nbsp;&amp;nbsp;&amp;nbsp; x += 1&amp;nbsp; del list1, row.Sum_Count&lt;/X&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This script gives me the output as follows: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt; ================================ RESTART ================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Successfully created list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_0_step1_minus.tif']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Successfully created list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_0_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_1_step1_minus.tif']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Successfully created list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_0_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_1_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_2_step1_minus.tif']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Successfully created list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_0_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_1_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_2_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_3_step1_minus.tif']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Successfully created list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_0_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_1_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_2_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_3_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_4_step1_minus.tif']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Successfully created list1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_0_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_1_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_2_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_3_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_4_step1_minus.tif', u'E:\\Models_Ken\\PSI_Outputs\\Test_Small_Run\\PSI_Census_SourceCalculation_5_step1_minus.tif']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;164&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;122&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "E:\Models_Ken\PSI_Outputs\Scripts\PSI_Multiply.py", line 41, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inParcelNumber = row.Sum_Count&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'NoneType' object has no attribute 'Sum_Count'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------------------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see, my list 1 is populated with the rasters I specified. The last set of numbers being 0,6,164,122,9,0 are the values that I am pulling out of the shapefiles Sum_Count field. These would be the values that I am looking to do my multiplication by, but instead of these values being stored in a list I am only able to print them out in this fashion.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry if this is confusing what I am trying to do by how I am describing it here, if anyone has any thoughts or questions about what I am trying to do I would really appreciate the feedback.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Zach Ancona&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Apr 2013 20:53:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71947#M5923</guid>
      <dc:creator>ZachAncona</dc:creator>
      <dc:date>2013-04-26T20:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python script that will create a list of a shapefiles values in a field.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71948#M5924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not really clear on what you are trying to do, but you seem to want a list of the values in the Sum_Count field.&amp;nbsp; All you have to do is replace your code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;rows = arcpy.SearchCursor(featureClass) row = rows.next() while row: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.Sum_Count &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;rows = arcpy.SearchCursor(featureClass) value_lst = [row.Sum_Count for row in rows]&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now you'll have a list of the values in the Sum_Count field, and you can do what you want with them later in the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error you were getting was raised when you tried to reference the row object after the last next() call, which always returns None when the end-of-file is encountered.&amp;nbsp; Use a value from the value_lst instead, and that error will go away.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Apr 2013 23:09:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71948#M5924</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2013-04-27T23:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python script that will create a list of a shapefiles values in a field.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71949#M5925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks I will give this a try when I get back to the office next week. Thank you for the reply!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Zach&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Apr 2013 23:36:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71949#M5925</guid>
      <dc:creator>ZachAncona</dc:creator>
      <dc:date>2013-04-27T23:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python script that will create a list of a shapefiles values in a field.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71950#M5926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Worked like a charm! If you are interested in what I was doing with the lists I have attached the working code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
from arcpy.sa import *

arcpy.CheckOutExtension("Spatial")

env.workspace = r"E:\Models_Ken\PSI_Outputs\Subtraction_Output_Tract"

list1 = []

lstRasters = arcpy.ListRasters("*")
for raster in lstRasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp; list1.append(env.workspace + os.sep + raster)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Successfully created list1'
&amp;nbsp;&amp;nbsp;&amp;nbsp; print list1

featureClass = r"E:\Models_Ken\PSI_Outputs\tract_centroids.shp"


rows = arcpy.SearchCursor(featureClass)
value_lst = [row.Sum_Count for row in rows]

print value_lst

count = len(list1)

x = 0
while x &amp;lt; count:
&amp;nbsp;&amp;nbsp;&amp;nbsp; raster = list1&lt;X&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; name = raster.split("\\")[-1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; inParcelNumber = value_lst&lt;X&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; outTimes = Times(raster, inParcelNumber)
&amp;nbsp;&amp;nbsp;&amp;nbsp; outTimes.save(r"E:\Models_Ken\PSI_Outputs\Multiplication_Output_Tract" + os.sep + name.split(".")[0] + "_multi.tif")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Successfully created raster'
&amp;nbsp;&amp;nbsp;&amp;nbsp; x += 1

del list1, value_lst, count&lt;/X&gt;&lt;/X&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Zach&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:47:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71950#M5926</guid>
      <dc:creator>ZachAncona</dc:creator>
      <dc:date>2021-12-10T22:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Python script that will create a list of a shapefiles values in a field.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71951#M5927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I see now.&amp;nbsp; Glad you got it working!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 22:29:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-that-will-create-a-list-of-a/m-p/71951#M5927</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2013-04-30T22:29:33Z</dc:date>
    </item>
  </channel>
</rss>

