I have four markets 1-4, but I only want to do markets 2 and 3. I created a markets list only containing those two markets so that I could use the list in a "for" loop. However, when I try and run it, it still runs through all the markets. I think this has to do with my "whereclause" or "sqlclause" or both, but I can't figure out how to fix it. I've tried using a wildcard in the "whereclause" but that doesn't work. I've also tried getting rid of the "whereclause" but that also doesn't work. Could someone help me with this?
-
fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Centers'</SPAN>
fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'market_id'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Center_ID'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Center_Name'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Opening_Date'</SPAN><SPAN class="punctuation token">]</SPAN>
fieldname <SPAN class="operator token">=</SPAN> <SPAN class="string token">'market_id'</SPAN>
<SPAN class="comment token">#Define WHERE clause statement</SPAN>
<SPAN class="comment token">#whereclause = """{} = '%000' """.format(arcpy.AddFieldDelimiters(fc, fieldname))</SPAN>
sqlclause <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Order By market_id, Center_ID'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Set Markets to loop through</SPAN>
markets <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Set Years to loop through</SPAN>
years <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2016</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">2017</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Set Months to loop through</SPAN>
months <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#returns last day of each month</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">last_day_of_month</SPAN><SPAN class="punctuation token">(</SPAN>any_day<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
next_month <SPAN class="operator token">=</SPAN> any_day<SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN>day<SPAN class="operator token">=</SPAN><SPAN class="number token">28</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> datetime<SPAN class="punctuation token">.</SPAN>timedelta<SPAN class="punctuation token">(</SPAN>days<SPAN class="operator token">=</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> next_month <SPAN class="operator token">-</SPAN> datetime<SPAN class="punctuation token">.</SPAN>timedelta<SPAN class="punctuation token">(</SPAN>days<SPAN class="operator token">=</SPAN>next_month<SPAN class="punctuation token">.</SPAN>day<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> market <SPAN class="keyword token">in</SPAN> markets<SPAN class="punctuation token">:</SPAN>
sqlclause <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Order By market_id, Center_ID'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>market<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> year <SPAN class="keyword token">in</SPAN> years<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>year<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> month <SPAN class="keyword token">in</SPAN> months<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>month<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>in_table <SPAN class="operator token">=</SPAN> fc<SPAN class="punctuation token">,</SPAN> field_names <SPAN class="operator token">=</SPAN> fields<SPAN class="punctuation token">,</SPAN> where_clause<SPAN class="operator token">=</SPAN>whereclause<SPAN class="punctuation token">,</SPAN> sql_clause<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">(</SPAN>None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'ORDER BY market_id, Center_ID'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>