<?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 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656744#M51104</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd suspect, based on your code, that you only have one argument passing to your script. In that case you would want sys.argv[0]. In Python, as in most computer languages, counting starts at 0.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 May 2012 16:43:52 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2012-05-08T16:43:52Z</dc:date>
    <item>
      <title>IndexError: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656743#M51103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am new to Python programming and I am trying to see if a working directory is there and if not create it.&amp;nbsp; I keep getting the following error IndexError: list index out of range.&amp;nbsp; Not sure what I am doing wrong.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I would appreciate it if anyone can lend some assistance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import string, sys, shutil, glob, os, arcpy&amp;nbsp; #print sys.argv&amp;nbsp; print arcpy.CheckOutExtension("Spatial") from arcpy.sa import * arcpy.env.overwriteOutput = True&amp;nbsp; #check to see if scratch directory exists: if os.path.isdir(sys.argv[1] + "/working")&amp;lt;&amp;gt; True: &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateArcInfoWorkspace_management(sys.argv[1], "working") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isdir(sys.argv[1] + "/output")&amp;lt;&amp;gt; True: &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateArcInfoWorkspace_management(sys.argv[1], "output") arcpy.AddMessage ("Output workspace created")&amp;nbsp; arcpy.env.workspace = sys.argv[1]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 16:27:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656743#M51103</guid>
      <dc:creator>JoanBiediger</dc:creator>
      <dc:date>2012-05-08T16:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656744#M51104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd suspect, based on your code, that you only have one argument passing to your script. In that case you would want sys.argv[0]. In Python, as in most computer languages, counting starts at 0.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 16:43:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656744#M51104</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-05-08T16:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656745#M51105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'd suspect, based on your code, that you only have one argument passing to your script. In that case you would want sys.argv[0]. In Python, as in most computer languages, counting starts at 0.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sys.argv[0] should be the name of the script. sys.argv[1] would be the first parameter. This is different than GetParameterAsText.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unless you're going to be working with Arc/INFO coverages, you probably don't want to use CreateArcInfoWorkspace. Use os.mkdir to create a directory for storing shapefiles, or CreateFileGDB for a file geodatabase.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 17:27:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656745#M51105</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-05-08T17:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656746#M51106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;sys.argv[0] should be the name of the script. sys.argv[1] would be the first parameter. This is different than GetParameterAsText.&lt;BR /&gt;&lt;BR /&gt;Joan,&lt;BR /&gt;&lt;BR /&gt;Unless you're going to be working with Arc/INFO coverages, you probably don't want to use CreateArcInfoWorkspace. Use os.mkdir to create a directory for storing shapefiles, or CreateFileGDB for a file geodatabase.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ah that's right. The only time I've used sys.argv I was doing processing using the script name as an input, that's probably how I got turned around.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 17:49:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656746#M51106</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-05-08T17:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656747#M51107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I keep getting the following error IndexError: list index out of range. Not sure what I am doing wrong.&lt;BR /&gt; &lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Might sound silly, but the only thing I can think of is that you haven't entered a value for the parameter, sys.argv[1]. Have you (ie. when you run the script, do you indicate which folder you want?)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does this work? It should.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, sys

arcpy.AddMessage(sys.argv[1])
print(sys.argv[1])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:48:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656747#M51107</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T03:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656748#M51108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Darren,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think you are right, when I print the sys.argv[1] I am getting the folder and the name of the script when what I really want to do is see if a folder exists in the same folder as the script and if &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;it doesn't then create the folder.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your response, I'll keep working on it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 21:01:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656748#M51108</guid>
      <dc:creator>JoanBiediger</dc:creator>
      <dc:date>2012-05-08T21:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: get folder location of python script</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656749#M51109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;what I really want to do is see if a folder exists in the same folder as the script and if &lt;BR /&gt;it doesn't then create the folder.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;sys.argv[0]&lt;/STRONG&gt;&lt;SPAN&gt; is the path of the script. I think this is what you're trying to do:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import sys import os import arcpy&amp;nbsp; # create a scratch folder in the same folder as the script Here = os.path.dirname(sys.argv[0]) if not arcpy.exists(os.path.join(Here,"working"): &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateArcInfoWorkspace_management(Here, "working")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 00:23:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656749#M51109</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-05-09T00:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: IndexError: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656750#M51110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Curtis,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help, that did the trick.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 12:19:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/indexerror-list-index-out-of-range/m-p/656750#M51110</guid>
      <dc:creator>JoanBiediger</dc:creator>
      <dc:date>2012-05-09T12:19:34Z</dc:date>
    </item>
  </channel>
</rss>

