<?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: Problem with expression using select by attributes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-expression-using-select-by-attributes/m-p/751484#M58058</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perhaps ACFDia is being imported as a float/double, but you are asking if it is equivalent to a string... You could try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;Select(AC_Fail,"NEW_SELECTION",str(ACFDia) + ' = ' + str(x))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If that doesn't help, try checking that it is coming through the way you expect it with something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(str(ACFDia)+str(type(ACFDia)))&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 Jul 2011 22:21:25 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2011-07-26T22:21:25Z</dc:date>
    <item>
      <title>Problem with expression using select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-expression-using-select-by-attributes/m-p/751483#M58057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have been working on a code to automate the process of finding the relative probability of failure for all of the water mains in a city and am having a problem using select by attributes. The code gives me an error saying "invalid expression". I have narrowed it down to this line: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
Select(AC_Fail,"NEW_SELECTION",ACFDia + ' = ' + str(x))
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know this is the line giving me problems because I commented it out and the rest of the script ran fine. The line before is written the exact same way, but it works. (Weird)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below, I have included everything in my script just to past the point where I am getting the error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy, sys
arcpy.env.workspace = "C:\Data\ArcGIS\Default.gdb"

#Define input and output variables
WaterPipes = sys.argv[1]
WPID = sys.argv[2]
WDia = sys.argv[3]
YearInst = sys.argv[4]
AC_Fail = sys.argv[5]
ACFDia = sys.argv[6]
SoftPunky = sys.argv[7]
PipeTests = sys.argv[8]
FailCategory = sys.argv[9]
ServiceFail = sys.argv[10]
OEM = sys.argv[11]
Probability = sys.argv[12]

#Define variables to make code readable
Select = arcpy.SelectLayerByAttribute_management
SpatialJoin = arcpy.SpatialJoin_analysis
Merge = arcpy.Merge_management
AddField = arcpy.AddField_management
MakeLayer = arcpy.MakeFeatureLayer_management
Calculate = arcpy.CalculateField_management
JoinField = arcpy.JoinField_management
Delete = arcpy.Delete_management

#Clear any selections on all input layers
Select(WaterPipes, "CLEAR_SELECTION")
Select(AC_Fail, "CLEAR_SELECTION")
Select(SoftPunky, "CLEAR_SELECTION")
Select(PipeTests, "CLEAR_SELECTION")
Select(ServiceFail, "CLEAR_SELECTION")

#Define pipe sizes
dia = []
rows = arcpy.SearchCursor(WaterPipes,"","",WDia,"")

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if getattr(row, WDia) not in dia:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dia.append(int(getattr(row, WDia)))

#For each pipe size, select all pipes of that size on the water pipes layer and the AC failure layer
#Join the two layers together to create a layer that counts the number of
#failures on the same diameter of pipe within 100 feet.
layers = []
for x in dia:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Select(WaterPipes,"NEW_SELECTION",WDia + ' = ' + str(x))
&amp;nbsp;&amp;nbsp;&amp;nbsp; Select(AC_Fail,"NEW_SELECTION",ACFDia + ' = ' + str(x))
&amp;nbsp;&amp;nbsp;&amp;nbsp; SpatialJoin(WaterPipes,AC_Fail,'Fail100' + str(x),"JOIN_ONE_TO_ONE","KEEP_ALL","","INTERSECT",100,"Dist")
&amp;nbsp;&amp;nbsp;&amp;nbsp; layers.append('Fail100' + str(x))

#Merge all of the different pipe size layers together into one layer.
Merge(layers,"Fail100ft")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why isn't this working?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help is much appreciated. If I haven't included enough information, let me know. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jul 2011 20:04:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-expression-using-select-by-attributes/m-p/751483#M58057</guid>
      <dc:creator>MatthewStrand</dc:creator>
      <dc:date>2011-07-26T20:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with expression using select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-expression-using-select-by-attributes/m-p/751484#M58058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perhaps ACFDia is being imported as a float/double, but you are asking if it is equivalent to a string... You could try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;Select(AC_Fail,"NEW_SELECTION",str(ACFDia) + ' = ' + str(x))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If that doesn't help, try checking that it is coming through the way you expect it with something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(str(ACFDia)+str(type(ACFDia)))&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jul 2011 22:21:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-expression-using-select-by-attributes/m-p/751484#M58058</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2011-07-26T22:21:25Z</dc:date>
    </item>
  </channel>
</rss>

