<?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: IndexError: list index out of range when using variable in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201319#M7621</link>
    <description>&lt;P&gt;Isn't original_globalid already a string with quotes? Are you putting an extra set of quotes around the string?&lt;/P&gt;</description>
    <pubDate>Wed, 10 Aug 2022 14:14:04 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2022-08-10T14:14:04Z</dc:date>
    <item>
      <title>IndexError: list index out of range when using variable</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201280#M7620</link>
      <description>&lt;P&gt;I am following the example within &lt;A href="https://developers.arcgis.com/python/guide/editing-features/" target="_blank" rel="noopener"&gt;Editing Features:&lt;/A&gt; to select a feature within the feature layer.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;sfo_feature&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;f&lt;/SPAN&gt; &lt;SPAN class=""&gt;for&lt;/SPAN&gt; &lt;SPAN class=""&gt;f&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; &lt;SPAN class=""&gt;ports_features&lt;/SPAN&gt; &lt;SPAN class=""&gt;if&lt;/SPAN&gt; &lt;SPAN class=""&gt;f&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;attributes&lt;/SPAN&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;'port_name'&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;SPAN class=""&gt;==&lt;/SPAN&gt;&lt;SPAN class=""&gt;'SAN FRANCISCO'&lt;/SPAN&gt;&lt;SPAN class=""&gt;][&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;The code is successful when hard-coding the value, as with 'SAN FRANCISCO' above, but fails with IndexError: list index out of range when using a variable. Following is my code:&lt;/P&gt;&lt;P&gt;The following is successful:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;obs_feature = [f for f in obs_features if f.attributes['globalid']=='18d8c3ac-f828-4d93-b4e8-8a3b281f1790'][0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And, the following is successful:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;globalid = '18d8c3ac-f828-4d93-b4e8-8a3b281f1790'
obs_feature = [f for f in obs_features if f.attributes['globalid']==globalid][0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following fails, with IndexError: list index out of range when using a variable.&amp;nbsp; I know the value is correct via the use of AddMessage to know the value being queried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;globalid = "'"+original_globalid+"'"
arcpy.AddMessage("globalid: {}".format(globalid)+"; fld: {}".format(fld)+"; fld_value: {}".format(fld_value))
obs_feature = [f for f in obs_features if f.attributes['globalid']==globalid][0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume this is something simple, but can't figure out the problem. I've tried format(globalid), although that shouldn't be necessary, but that fails as well.&lt;/P&gt;&lt;P&gt;Someone, please save me from myself!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 13:38:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201280#M7620</guid>
      <dc:creator>WhitneyWeber</dc:creator>
      <dc:date>2022-08-10T13:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range when using variable</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201319#M7621</link>
      <description>&lt;P&gt;Isn't original_globalid already a string with quotes? Are you putting an extra set of quotes around the string?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 14:14:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201319#M7621</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-08-10T14:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range when using variable</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201455#M7622</link>
      <description>&lt;P&gt;Sorry, no, it's not already a string with quotes. . I should have put the result of the AddMessage:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;globalid: '18d8c3ac-f828-4d93-b4e8-8a3b281f1790'; fld: EO_ID; fld_value: 300997.0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, you can see the globalid from the AddMessage is the same as what was hardcoded in the code that works. It just doesn't work when using the variable.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 17:48:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201455#M7622</guid>
      <dc:creator>WhitneyWeber</dc:creator>
      <dc:date>2022-08-10T17:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range when using variable</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201467#M7623</link>
      <description>&lt;P&gt;However, note that the fld value is also a string and doesn't have quotes.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 18:07:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201467#M7623</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-08-10T18:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range when using variable</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201547#M7624</link>
      <description>&lt;P&gt;You're a genius! I was obviously over-thinking this. Thank you so much! It always helps to have someone else's view.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 20:13:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/indexerror-list-index-out-of-range-when-using/m-p/1201547#M7624</guid>
      <dc:creator>WhitneyWeber</dc:creator>
      <dc:date>2022-08-10T20:13:22Z</dc:date>
    </item>
  </channel>
</rss>

