<?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: sys.argv/raw input question in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180839#M13870</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You might want to look into the Tkinter module as well.&amp;nbsp; That will allow you to browse for file/folder using the windows explorer type interface.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure what your rasters are as it won't see inside FGDB's, but if they are stand alone files, you may be able to use Tkinter to browse to and select.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Jul 2013 22:33:01 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2013-07-24T22:33:01Z</dc:date>
    <item>
      <title>sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180832#M13863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a piece of code where I want the user to be able to specify the rasters that will be used in the mosaic tool etc but I'm having a bit of trouble. Could anybody please point me in the right direction regarding what I'm doing wrong and how to get the user to be able to input the rasters below. Thank you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Prints the length of sys.argv and the first argument
print 'Number of Arguments = ', len(sys.argv)
print 'First Argument sys.argv[0] = ', sys.argv[0]
if len(sys.argv)==1:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Workspace = raw_input("Please enter the folder path of your workspace")
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_1 = raw_input("Please enter the path to the first raster")
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_2 = raw_input("Please enter the path to the second raster")
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_3 = raw_input("Please enter the path to the third raster")
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_4 = raw_input("Please enter the path to the fourth raster")
&amp;nbsp;&amp;nbsp;&amp;nbsp; BufferDistance = raw_input("Please enter the required buffer distance")
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Workspace = sys.argv[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_1 = sys.argv[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_2 = sys.argv[3]
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_3 = sys.argv[4]
&amp;nbsp;&amp;nbsp;&amp;nbsp; Raster_4 = sys.argv[5]
&amp;nbsp;&amp;nbsp;&amp;nbsp; BufferDistance = sys.argv[6]
#User enters the workspace path
arcpy.env.workspace = out_path = Workspace
print 'Workspace Set'
# Create Raster Dataset
out_name = "R_Dataset"
# Run the Create Raster Dataset Script
arcpy.CreateRasterDataset_management (out_path, out_name, "", "8_BIT_UNSIGNED", "", "1", "", "PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP", "128 128", "LZ77", "")
# Mosaic Rasters into the Raster Dataset
Raster_inputs = (sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
# Set the target to the Raster Dataset that was already created&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 18:15:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180832#M13863</guid>
      <dc:creator>DonalCasey</dc:creator>
      <dc:date>2013-07-24T18:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180833#M13864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;1. What exactly is the problem you are having?&amp;nbsp; error?&amp;nbsp; nothing happens?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. This doesn't look right (maybe it is, but I have never set a workspace like this): &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.env.workspace = out_path = Workspace&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Why raw input?&amp;nbsp; What if they type in an incorrect path or raster?&amp;nbsp; Seems like this is much better suited for a Toolbox that you can add input parameters for the individual rasters and the workspace itself.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 18:23:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180833#M13864</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-07-24T18:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180834#M13865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;what is the error?&amp;nbsp; Why not just use the syntax of the mosaic tool rather than coding rawinput stuff?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 18:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180834#M13865</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-07-24T18:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180835#M13866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm getting an error that says: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"Index Error: list index out of range'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't know how to do it besides using raw_inputs? and I also don't know how to have an alternative scenario if they type the wrong file name, apologies for my ignorance, I'm very new to Python.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 18:46:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180835#M13866</guid>
      <dc:creator>DonalCasey</dc:creator>
      <dc:date>2013-07-24T18:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180836#M13867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm getting an error that says: &lt;BR /&gt;&lt;BR /&gt;"Index Error: list index out of range'&lt;BR /&gt;&lt;BR /&gt;Any ideas?&lt;BR /&gt;&lt;BR /&gt;I don't know how to do it besides using raw_inputs? and I also don't know how to have an alternative scenario if they type the wrong file name, apologies for my ignorance, I'm very new to Python.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe have a look at some great resources in the ESRI library to get you started:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/A_quick_tour_of_creating_custom_tools/001500000001000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/A_quick_tour_of_creating_custom_tools/001500000001000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I picked this because it appears you need to start by making a choice between developing with Model Builder or jump into creating Toolbox components.&amp;nbsp; Entirely up to you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry I don't have a direct answer to your OP.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 18:59:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180836#M13867</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-07-24T18:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180837#M13868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It's my understanding that sys.argv begins with 1, so the sys.argv[0] might be throwing the "out of range" error. Though I may be misunderstanding how that sys.argv[0] line is being used. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Additionally, are you using PythonWin to be using the raw_input? While it is nice to use in PythonWin, raw_input won't work elsewhere. When I am running scripts with lots of sys.argv in PythonWin, I write it all out in a text file that I keep on hand to copy/paste. Though, as mentioned, user input errors will cause it to error as well. If this will ultimately be a script in ArcToolbox, I would make them sys.argv.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would also set the out_path as such: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;out_path = arcpy.env.workspace = Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If that doesn't work, break it to two lines&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_path = arcpy.env.workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps, but I am pretty new to Python too. Good luck!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 19:43:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180837#M13868</guid>
      <dc:creator>AlisonMontgomery</dc:creator>
      <dc:date>2013-07-24T19:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180838#M13869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;sys.argv[0] is the scripts name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sys.argv[1] is equivalent to arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 21:45:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180838#M13869</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-07-24T21:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: sys.argv/raw input question</title>
      <link>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180839#M13870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You might want to look into the Tkinter module as well.&amp;nbsp; That will allow you to browse for file/folder using the windows explorer type interface.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure what your rasters are as it won't see inside FGDB's, but if they are stand alone files, you may be able to use Tkinter to browse to and select.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 22:33:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sys-argv-raw-input-question/m-p/180839#M13870</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-07-24T22:33:01Z</dc:date>
    </item>
  </channel>
</rss>

