<?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: Need help with a calculate Python Print Statement script for ArcMap in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-help-with-a-calculate-python-print-statement/m-p/329638#M25649</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is CLASS a string or number field?&amp;nbsp; If the former, it will generate the same error you are seeing when you try to treat it like a number, which you are doing.&amp;nbsp; If the field is a string, try the following:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;clip_output&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'Hectares'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"CLASS in ('1', '2')"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 05 Nov 2016 18:00:49 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2016-11-05T18:00:49Z</dc:date>
    <item>
      <title>Need help with a calculate Python Print Statement script for ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-a-calculate-python-print-statement/m-p/329637#M25648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To finish off my script tool i want the script to give me an add message (sum) that calculates total hectares for only 2 certain attributes (soil classes 1 and 2) in my Hectares field. I have a hectares field and a field that give soil classes 1 to 5. in the python language how would i write the expression?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The shapefile i want to perform this on is called: [clip_output] &amp;nbsp;&lt;/P&gt;&lt;P&gt;The field thats lists soil type is called: [CLASS] &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;The hectares field that I want the script to give me the sum from is called [Hectares] &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I have so far but it is not working (not sure if i need to list variables):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(clip_output, ['Hectares'], 'CLASS in (1, 2)') as cur:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum = 0&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cur:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum += row[0]&lt;/P&gt;&lt;P&gt;arcpy.AddMessage(sum)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;error im getting is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; font-size: 13px;"&gt;line 106, in &amp;lt;module&amp;gt; for row in cur: RuntimeError: An invalid SQL statement was used&lt;/SPAN&gt;&lt;SPAN style="color: #242729; background-color: rgba(248, 248, 248, 0.6);"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Nov 2016 15:38:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-a-calculate-python-print-statement/m-p/329637#M25648</guid>
      <dc:creator>Noah_McLaughlin</dc:creator>
      <dc:date>2016-11-05T15:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a calculate Python Print Statement script for ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-a-calculate-python-print-statement/m-p/329638#M25649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is CLASS a string or number field?&amp;nbsp; If the former, it will generate the same error you are seeing when you try to treat it like a number, which you are doing.&amp;nbsp; If the field is a string, try the following:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;clip_output&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'Hectares'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"CLASS in ('1', '2')"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Nov 2016 18:00:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-a-calculate-python-print-statement/m-p/329638#M25649</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-11-05T18:00:49Z</dc:date>
    </item>
  </channel>
</rss>

