<?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: Basic python in ArcGIS, need help! in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610413#M47661</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are amazing, thank you so much. So far in this class it has been difficult because the prof expects us to learn withotu much guidance other than vague walkthroughs in the assigned labs that dont really show me how to do anything the question asks. The explanations on this was great i really appreciate you taking the time to help me learn this, a majority of the labs i have been searching ESRI extensively to find out what im trying to do is simple with the right codes -.- Its a graduate class offered to undergrads to help us land jobs after finishing school&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Apr 2014 16:29:21 GMT</pubDate>
    <dc:creator>JacobWagner</dc:creator>
    <dc:date>2014-04-22T16:29:21Z</dc:date>
    <item>
      <title>Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610410#M47658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay, so i had to take this copy of the random_sample.py script and call it&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;random_percent.py. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now im being asked to modify the script so that the third parameter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;is a percentage of the number of input records as an integer between&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 and 100. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And then modify the script tool settings so that the input for this parameter is validated on the tool dialog box.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm still relatively new to python so it all sounds like jargon to me and after trying multiple times to figure it out i still can't find the proper code to use.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using python in ArcMap, and have read the chapter in pyrhon scripting for ArcGIS and am still stumped. How do i do this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Apr 2014 22:54:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610410#M47658</guid>
      <dc:creator>JacobWagner</dc:creator>
      <dc:date>2014-04-21T22:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610411#M47659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry i have the code file attached on this part&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Apr 2014 22:56:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610411#M47659</guid>
      <dc:creator>JacobWagner</dc:creator>
      <dc:date>2014-04-21T22:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610412#M47660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Hello Jacob,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Python is awesome. It can be tricky to learn, but it's great once you do. In the future, it would be a lot easier if you posted the python code as text in your posting (see &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/48475-Please-read-How-to-post-Python-code" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt; for instructions).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I've made your requested changes to the script and tried to add lots of comments (text after "#" are comments) to help you understand whats going on:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;#import modules you'll need in your script: 
import arcpy 
import random 
from arcpy import env&amp;nbsp; 

#allow outputs to be overwritten 
#(so you don't have to delete them before each time you run&amp;nbsp; 
env.overwriteoutput = True 

#set input variables: 
inputfc = "C:/EsriPress/Python/Date/Exercise13/points.shp" 
outputic = "C:/EsriPress/Python/Data/Exercise13/Results/random.shp" 
pctRecords = 50&amp;nbsp; 

#empty lists for later use: 
inlist = [] 
randomlist = []&amp;nbsp; 

#get the unique id field for the input feature class 
desc = arcpy.Describe(inputfc) 
fldname = desc.OIDFieldName&amp;nbsp; 

#iterate through the input feature class (see below for an alternative to the while loop)

#get the rows for the input feature class (this is similar to the attribute table) 
rows = arcpy.SearchCursor(inputfc) 
row = rows.next() #get the next single row (in this case, it's the first row) 
count=0&amp;nbsp; #set a counter to 0 
#while row exists, do some stuff:
while row: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; id = row.getValue(fldname) #get the id from the current row&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; inlist.append(id) #add that id to a list we created earlier&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; count+=1 #add one to our counter&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next() #switch to the next row&amp;nbsp; 

#Now that we have the count we can set our outcount 
#first turn input percent to a deciman (example 0.5 instead of 50), 
#then times it by the count&amp;nbsp; 
outcount = (pctRecords*0.01)*count&amp;nbsp; 

while len(randomlist) &amp;lt; outcount: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #while the randomlist is smaller than the desired outcount:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; selitem = random.choice(inlist) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #pick a random item from the list we created in the previous while loop&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; randomlist.append(selitem) #add that randomly picked id to the random list&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; inlist.remove(selitem) #remove that id from the list so it won't randomly get picked again&amp;nbsp; 

#create a sql statement to do a select by attribute: 
sqlexp = '"' + fldname + '"' + ' in ' + '(' + str(randomlist)[1:-1] + ')'&amp;nbsp; 
#make a selection by selecting all the id's in the random list from the original file 
arcpy.MakeFeatureLayer_management(inputfc, "selection", sqlexp)&amp;nbsp; 
#turn that selection into a shapefile: 
arcpy.CopyFeatures_management("selection", outputfc)&amp;nbsp; 
print "Script is complete!"
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

As an alternative to your first while loop, I would prefer to use a for loop (but either will work). This is what the for loop would loop like:
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#iterate through the input feature class (alternative to the while loop) rows = arcpy.SearchCursor(inputfc) #get the rows for the input feature class (this is similar to the attribute table) count=0 #set a counter to 0 for row in rows: #goes through each row in rows and does stuff with that row&amp;nbsp; id = row.getValue(fldname) #get the id from the current row&amp;nbsp; inlist.append(id) #add that id to a list we created earlier&amp;nbsp; count+=1 #add one to our counter&lt;/PRE&gt;&lt;DIV style="display: none;"&gt; &lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Let me know if you have any questions. Good luck!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:07:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610412#M47660</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2021-12-12T02:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610413#M47661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are amazing, thank you so much. So far in this class it has been difficult because the prof expects us to learn withotu much guidance other than vague walkthroughs in the assigned labs that dont really show me how to do anything the question asks. The explanations on this was great i really appreciate you taking the time to help me learn this, a majority of the labs i have been searching ESRI extensively to find out what im trying to do is simple with the right codes -.- Its a graduate class offered to undergrads to help us land jobs after finishing school&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 16:29:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610413#M47661</guid>
      <dc:creator>JacobWagner</dc:creator>
      <dc:date>2014-04-22T16:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610414#M47662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How do i submit that you answered what i had asked to give you credit for it?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 16:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610414#M47662</guid>
      <dc:creator>JacobWagner</dc:creator>
      <dc:date>2014-04-22T16:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610415#M47663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;How do i submit that you answered what i had asked to give you credit for it?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hit the check mark on the right side of his post that answered your question.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 16:38:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610415#M47663</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2014-04-22T16:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610416#M47664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;done, and thank you&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 16:48:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610416#M47664</guid>
      <dc:creator>JacobWagner</dc:creator>
      <dc:date>2014-04-22T16:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610417#M47665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jacob (and John!),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm happy you were able to understand my comments. I had a great python prof, but I still spent a lot of my time lost, confused and searching google (this forum and &lt;/SPAN&gt;&lt;A href="http://stackoverflow.com"&gt;stackoverflow.com&lt;/A&gt;&lt;SPAN&gt; are &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;great&lt;/SPAN&gt;&lt;SPAN&gt; resources). Ask again (on this posting or a new one) if you hit another brick wall. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS. Good luck finding a job. I just repeatedly told python and GIS were a 'golden tickets' on my resume and it still took me a bit over a year. Don't get discouraged, but be prepared for a challenge.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 16:56:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610417#M47665</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2014-04-22T16:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610418#M47666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jacob,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please, can you help me with the solution to this question. you can email me please, &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:jucoy2k@hotmail.com"&gt;jucoy2k@hotmail.com&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 23 Apr 2017 04:03:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610418#M47666</guid>
      <dc:creator>UcheJames</dc:creator>
      <dc:date>2017-04-23T04:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Basic python in ArcGIS, need help!</title>
      <link>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610419#M47667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;and to add to the comment about the forums, etc.&amp;nbsp; There are many threads here on GeoNet that list different resources for helping to learn Python.&amp;nbsp; I just did a search for "learn python" in Geonet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;note: "API for Python" is different than Python.&amp;nbsp; The API is fairly new and would be good to learn, but would cause confusion when you are still learning Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check out some of these threads for some tips on python:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/thread/185878"&gt;Can anyone suggest a good learning python website?&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/thread/146327"&gt;Best book for learning Python&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/message/85013"&gt;https://community.esri.com/message/85013&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/05/09/the-links?sr=search&amp;amp;searchId=63ade22a-5b81-4e38-a2a3-e434c9fd94ba&amp;amp;searchIndex=3"&gt;/blogs/dan_patterson/2016/05/09/the-links?sr=search&amp;amp;searchId=63ade22a-5b81-4e38-a2a3-e434c9fd94ba&amp;amp;searchIndex=3&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(not in any particular order)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Apr 2017 15:26:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-python-in-arcgis-need-help/m-p/610419#M47667</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2017-04-24T15:26:28Z</dc:date>
    </item>
  </channel>
</rss>

