<?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: Loop issue in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333564#M25992</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you set the workspace environment? That is a necessary step 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer to help &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/ListFeatureClasses/03q300000023000000/"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Dec 2015 17:30:38 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2015-12-22T17:30:38Z</dc:date>
    <item>
      <title>Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333563#M25991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a list of shapefiles that I need to select within a loop, to see if the file is there or not.&lt;/P&gt;&lt;P&gt;I tried several loops if, elif ... Just get an error???&lt;/P&gt;&lt;P&gt;I would appreciate any suggestions, to get this working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; #check file exists here?&lt;/P&gt;&lt;P&gt; fcList = arcpy.ListFeatureClasses()&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for shapefile in fcList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if shapefile == "Bus Stops":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "1" ++ shapefile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif shapefile == "Cluster_Sites":&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "2" ++ "shapefile"&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif shapefile == "Highway Boundary":&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "3" ++ "shapefile"&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif shapefile == "Street Lighting":&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "4" ++ "shapefile"&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif shapefile == "Road_Traffic_Collisions":&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "5" ++ "shapefile"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "end"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code prints:&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;&amp;lt;type file&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are 3 shapefiles in the directory.&lt;/P&gt;&lt;P&gt;There could be 0 to10 shapefiles&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 17:19:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333563#M25991</guid>
      <dc:creator>CliveSwan</dc:creator>
      <dc:date>2015-12-22T17:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333564#M25992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you set the workspace environment? That is a necessary step 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer to help &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/ListFeatureClasses/03q300000023000000/"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 17:30:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333564#M25992</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-12-22T17:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333565#M25993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;could you format your code using code blocks since there are indentation errors which may be real or the result of copying/pasting/font issues &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 17:31:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333565#M25993</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-12-22T17:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333566#M25994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Clive,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Right off the bat, you have some syntax issues with ++ in your string concatenation (as well as some indentation issues - maybe just artifacts?). Also, you are referring to shapefile as an object and "shapefile" as a string. Try fixing that, and if it still doesn't work, print shapefile to make sure you know what it's doing. Lastly, are you in the right workspace? I don't see any code setting this...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 17:32:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333566#M25994</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2015-12-22T17:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333567#M25995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;datadir = arcpy.env.workspace = r"D:/DATA/HML"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If directory doesn't exist make it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not os.path.isdir(datadir):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.mkdir(datadir)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Change the local directory to where you want to put the data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.chdir(datadir)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #check file exists here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in fcList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == "Bus Stops":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "1" ++&amp;nbsp; shapefile&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif i == "Cluster_Sites_2014":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print shapefile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "2"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print"error"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There code runs, the appearance is copy/paste.&lt;/P&gt;&lt;P&gt;If the indentation was wrong, it would not compile!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It prints:&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;&amp;lt;type file&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need the loop to work.&lt;/P&gt;&lt;P&gt;If the file exists it runs a command, then jumps to the next item.&lt;/P&gt;&lt;P&gt;If the file does not exist it jumps to the next item.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 17:50:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333567#M25995</guid>
      <dc:creator>CliveSwan</dc:creator>
      <dc:date>2015-12-22T17:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333568#M25996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your code block, where is &lt;STRONG&gt;shapefile&lt;/STRONG&gt; coming from? You still have an issue with your concatenation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="_jivemacro_uid_1450806891604658 jive_macro_code jive_text_macro" data-renderedposition="50_8_912_16" jivemacro_uid="_1450806891604658"&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;print "1" ++&amp;nbsp; shapefile&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That should result in something like &lt;SPAN style="color: #e23d39;"&gt;bad operand type for unary +: 'str'&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 17:55:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333568#M25996</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2015-12-22T17:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333569#M25997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, try just printing your item:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;for i in fcList:&lt;/SPAN&gt;
&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; print i&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:47:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333569#M25997</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2021-12-11T15:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333570#M25998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you print the list returned by ListFeatureClasses, you may notice that shapefiles include ".shp". Try comparing against, for example, "&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Cluster_Sites_2014.shp" rather than "&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Cluster_Sites_2014".&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 18:01:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333570#M25998</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-12-22T18:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333571#M25999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;If I type:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in fcList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print i&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I get the list of shapefiles as expected.&lt;/P&gt;&lt;P&gt;Cluster_sites.shp&lt;/P&gt;&lt;P&gt;Fixed and Mobile Camera.shp&lt;/P&gt;&lt;P&gt;Road_Traffic_Collisions.shp&lt;/P&gt;&lt;P&gt;&amp;lt;type 'file'&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The aim is to use the if, elif block to use the CopyFeature command, if the shapefile exsists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clive&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 18:04:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333571#M25999</guid>
      <dc:creator>CliveSwan</dc:creator>
      <dc:date>2015-12-22T18:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333572#M26000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in fcList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "1" ++ shapefile&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Returns an error&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 18:06:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333572#M26000</guid>
      <dc:creator>CliveSwan</dc:creator>
      <dc:date>2015-12-22T18:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Loop issue</title>
      <link>https://community.esri.com/t5/python-questions/loop-issue/m-p/333573#M26001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Darren,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, when I added the .shp the script worked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Got back &lt;/P&gt;&lt;P&gt;Cluster_sites.shp&lt;/P&gt;&lt;P&gt;Fixed and Mobile Camera.shp&lt;/P&gt;&lt;P&gt;Road_Traffic_Collisions.shp&lt;/P&gt;&lt;P&gt;&amp;lt;type 'file'&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Dec 2015 18:13:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-issue/m-p/333573#M26001</guid>
      <dc:creator>CliveSwan</dc:creator>
      <dc:date>2015-12-22T18:13:26Z</dc:date>
    </item>
  </channel>
</rss>

