<?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 IndexError list out of range in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282787#M21799</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, sys


workspace = sys.argv[1]
featureclass = sys.argv[2]


try:
&amp;nbsp; arcpy.env.workspace = workspace
&amp;nbsp; fields = arcpy.ListFields(featureclass)
&amp;nbsp; for fld in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fld
except:
 print arcpy.GetMessages()





&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error I am getting is :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\ArcpyBook\Appendix1\ListFields.py", line 3, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace = sys.argv[1]&lt;/P&gt;&lt;P&gt;IndexError: list index out of range&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:41:29 GMT</pubDate>
    <dc:creator>DEAF_PROBERT_68</dc:creator>
    <dc:date>2021-12-11T13:41:29Z</dc:date>
    <item>
      <title>IndexError list out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282787#M21799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, sys


workspace = sys.argv[1]
featureclass = sys.argv[2]


try:
&amp;nbsp; arcpy.env.workspace = workspace
&amp;nbsp; fields = arcpy.ListFields(featureclass)
&amp;nbsp; for fld in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fld
except:
 print arcpy.GetMessages()





&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error I am getting is :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\ArcpyBook\Appendix1\ListFields.py", line 3, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace = sys.argv[1]&lt;/P&gt;&lt;P&gt;IndexError: list index out of range&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:41:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282787#M21799</guid>
      <dc:creator>DEAF_PROBERT_68</dc:creator>
      <dc:date>2021-12-11T13:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError list out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282788#M21800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you collected any parameters in sys.argv[]? The error indicates you have not. You can check with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14258681557936173 jive_text_macro" data-renderedposition="50_8_912_16" jivemacro_uid="_14258681557936173"&gt;&lt;P&gt;print len(sys.argv)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should return 1 (which holds the name of the script) if no extra parameters have been specified.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2015 02:29:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282788#M21800</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-03-09T02:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError list out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282789#M21801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;also line 14 isn't indented properly&lt;/P&gt;&lt;P&gt;​and as Darren says...how are you running this? you don't show what you used as an input?&amp;nbsp; add in a couple of print statements so you can see the script name (ie sys.argv[0]) and the inputs (ie sys.argv[1])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2015 04:07:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282789#M21801</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-03-09T04:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError list out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282790#M21802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Dan Patterson &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, this code came from the book I am working on from Eric Pimpler's ebook "Programming ArcGIS 10.1 with Python cookbook. That book was in 2013&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes I find a lot of errors in that book however I tried to tweak some of the codes but was not able to figure it out and I thought there must be a way around to correct it..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2015 04:12:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282790#M21802</guid>
      <dc:creator>DEAF_PROBERT_68</dc:creator>
      <dc:date>2015-03-09T04:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError list out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282791#M21803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This code is meant to be run from a script tool with two parameters: workspace and feature class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your purposes, you can just enter values for each parameter (sorry, the code block won't let me format it correctly, so there are some indentation issues, but substituting values for the sys.argv parameters is the take-home message).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;OL class="dp-py" start="1"&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;import arcpy, sys&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;workspace = r'C:/someworkspace'&lt;SPAN class="number"&gt;&amp;nbsp; 
&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;featureclass = r'C:/somefolder/someGDB.gdb/somefeatureclass'&lt;SPAN class="number"&gt;
&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;try:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp; arcpy.env.workspace = workspace&amp;nbsp; &lt;/LI&gt;&lt;LI&gt;&amp;nbsp; fields = arcpy.ListFields(featureclass)&amp;nbsp; &lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;for fld &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; fields:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;print fld&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;except:&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;print arcpy.GetMessages()&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:41:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282791#M21803</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T13:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError list out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282792#M21804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​or if using your favorite IDE, check how you can enter parameters while running them.&amp;nbsp; I know Pythonwin pops up a dialog and you can enter the parameters directly so you don't need to hardcode them in a script&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2015 04:25:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-out-of-range/m-p/282792#M21804</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-03-09T04:25:25Z</dc:date>
    </item>
  </channel>
</rss>

