I am using ArcGIS Pro 2.4.3, and just running this script through IDLE for ArcGIS Pro.
I am having some difficulty getting a standard expression in Python to return what I need. I have created a simple query to try and run...if I can get this to work then I will insert this into my main program with added functions.
When I run the script it only returns 16 records (i.e. records for only for variable Q1_A). I'm trying to get it to return 18 records (which would include Q1_B).
<SPAN class="keyword token">import</SPAN> arcpy
Q1_A <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CHARLES HAYS"</SPAN>
Q1_B <SPAN class="operator token">=</SPAN> <SPAN class="string token">"SMIT CLYDE"</SPAN>
fc1 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"F:\ArcGIS_Pro_Projects\AIS\AIS_Data\AIS_Data.gdb\TEST_AIS_Data"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#expression1 = ("Vessel_Name = 'CHARLES HAYS' Or Vessel_Name = 'SMIT CLYDE'")</SPAN>
expression1 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Vessel_Name = '"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>Q1_A<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN> <SPAN class="operator token">or</SPAN> <SPAN class="string token">"Vessel_Name = '"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>Q1_B<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>expression1<SPAN class="punctuation token">)</SPAN>
SelectResult <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>fc1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>expression1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
CountTotal <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>fc1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
CountResult <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>SelectResult<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>CountResult<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" Of "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>CountTotal<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" Records Selected"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>fc1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CLEAR_SELECTION"</SPAN><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>Hardcoding it (as per what is commented out) works exactly as I need it to work, and returns 18 records.
If I use an "and" instead of an "or" it returns 2 records (only for Q1_B). Logic tells me that using an "or" it should select 18 records (i.e. for both Q1_A and Q1_B).
The print statement (e.g. print (expression1)) also only prints the variable Q1_A.
What am I doing wrong here? How do I get the variable "expression1" to read the entire string? I know I'm missing something, but for the life of me I just can't see it...and I have been spinning my wheels on this all afternoon.
Suggestions?
Thank you