<?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: Build a query string in Python in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715105#M2365</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about something like this? &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import string

##Variables separated "find it easier to work with when doing query strings"
lot_plan = 'LOT_PLAN'
equal = '='
recs = ['ab1','ab2','ab3','ab4']

##Set up string by concatenating each part
begQuery = '\"%s" %s ' %(lot_plan,equal)

## Empty list to hold values
query = []

##May not need this but put it in anyway
numRecs = len(recs)
print numRecs

for rec,i in zip(recs,range(numRecs)):
&amp;nbsp;&amp;nbsp;&amp;nbsp; totQuery = "%s '%s' OR" %(begQuery,rec)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print totQuery
&amp;nbsp;&amp;nbsp;&amp;nbsp; query.append(totQuery)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
## Then if you need it all in one string
x = ' '.join(str(s) for s in query)
print x


&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course apply it to your stuff the output it gives me is&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab1' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab2' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab3' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab4' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab1' OR "LOT_PLAN" =&amp;nbsp; 'ab2' OR "LOT_PLAN" =&amp;nbsp; 'ab3' OR "LOT_PLAN" =&amp;nbsp; 'ab4' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At the end you would need to cut off the OR or have a differnt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;variable or some sort of catch that if its the end of the record count use that&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helped&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 06:37:27 GMT</pubDate>
    <dc:creator>LindseyWood</dc:creator>
    <dc:date>2021-12-12T06:37:27Z</dc:date>
    <item>
      <title>Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715098#M2358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: chent&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi, I am trying to write a small Python script to build a query string so ArcGIS can use it to select data by attribute.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In this script it first reads a text file (attachments) with 5 lot/plan details (each in separate line), then build a single line query string accordingly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script to build the query string:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#===============&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;f_count = open("C:\GeoSpatialTraining\ArcGIS10\GISProgramming101\Exercises\Data\Local data\LotPlan_List.txt", "r")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Count records number&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;numRec = len(f_count.readlines())&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "There are " + str(numRec) + " records in the file."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;f = open("C:\GeoSpatialTraining\ArcGIS10\GISProgramming101\Exercises\Data\Local data\LotPlan_List.txt", "r")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sQuery = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;i = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for rec in f:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print rec&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i &amp;lt; numRec:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sQuery = sQuery + "\"LOT_PLAN\" = '" + rec + "' OR " &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sQuery = sQuery + "\"LOT_PLAN\" = '" + rec + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print sQuery&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;f.close()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print sQuery&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#======================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is what I'd expect as a result:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" = '68SP245201' OR "LOT_PLAN" = '7SP101558' OR "LOT_PLAN" = '8RP620660' OR "LOT_PLAN" = '8SP239672' OR "LOT_PLAN" = '9SP239672'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But it ends up like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" = '68SP245201&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;' OR "LOT_PLAN" = '7SP101558&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;' OR "LOT_PLAN" = '8RP620660&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;' OR "LOT_PLAN" = '8SP239672&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;' OR "LOT_PLAN" = '9SP239672&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anyone help please? Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 01:58:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715098#M2358</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-03-12T01:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715099#M2359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;reformat your code so that indentations are readily read&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 02:42:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715099#M2359</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-03-12T02:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715100#M2360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: chent&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;reformat your code so that indentations are readily read&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the reply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The indentations seem fine in my script, it's only when I paste the code in the message box here that all indentations were removed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attached the script in my first message, can you run it and see if it comes up with different result please? Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 02:49:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715100#M2360</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-03-12T02:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715101#M2361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Something like this should work for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os

file = r'C:\GeoSpatialTraining\ArcGIS10\GISProgramming101\Exercises\Data\Local data\LotPlan_List.txt'
f_count = open(file, "r")
#Count records number
numRec = len(f_count.readlines())
print("There are {0} records in the file.".format(numRec))
f = open(file, "r")
field = 'LOT_PLAN'
lots_list = []
for rec in f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rec = rec.rstrip('\n')
&amp;nbsp;&amp;nbsp;&amp;nbsp; lots_list.append(rec)
sQuery = '''"{0}" in ('{1}')'''.format(field, "', '".join(lots_list))
f.close()
print(sQuery)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:37:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715101#M2361</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T06:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715102#M2362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: recurvata&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The indentations seem fine in my script, it's only when I paste the code&amp;nbsp; in the message box here that all indentations were removed.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The indentations may be fine in your script, but it's helpful if you use code tags when posting code on the forum. Click the # symbol in the icon menu above the post entry form and paste your code in between the code tags. Or type the code tags. See pngs below. Besides allowing someone to check for an error there, it's much more legible.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 19:39:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715102#M2362</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-03-12T19:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715103#M2363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The indentations seem fine in my script, it's only when I paste the code in the message box here that all indentations were removed&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please read: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[thread]48475[/thread]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my attempt at a solution for you -- just to show your original syntax could work too. (I believe if the table is indexed by this field, the form may be slightly faster -- indexes are data-format dependent though so I'm not sure.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
queries = []
qry = '"LOT_PLAN" = \'{0}\''
for rec in f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; queries.append(qry.format(rec))
f.close()
sQuery = " OR ".join(queries)
print sQuery
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:37:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715103#M2363</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T06:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715104#M2364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: chent&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for that. I put your code in and run it, but it still comes up the same result.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the updated code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;f_count = open("C:\GeoSpatialTraining\ArcGIS10\GISProgramming101\Exercises\Data\Local data\LotPlan_List.txt", "r")
#Count records number
numRec = len(f_count.readlines())
print "There are " + str(numRec) + " records in the file."

f = open("C:\GeoSpatialTraining\ArcGIS10\GISProgramming101\Exercises\Data\Local data\LotPlan_List.txt", "r")
sQuery = ""
queries = []
qry = '"LOT_PLAN" = \'{0}\''
for rec in f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; queries.append(qry.format(rec))
f.close()
sQuery = " OR ".join(queries)
print sQuery&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:37:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715104#M2364</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T06:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715105#M2365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about something like this? &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import string

##Variables separated "find it easier to work with when doing query strings"
lot_plan = 'LOT_PLAN'
equal = '='
recs = ['ab1','ab2','ab3','ab4']

##Set up string by concatenating each part
begQuery = '\"%s" %s ' %(lot_plan,equal)

## Empty list to hold values
query = []

##May not need this but put it in anyway
numRecs = len(recs)
print numRecs

for rec,i in zip(recs,range(numRecs)):
&amp;nbsp;&amp;nbsp;&amp;nbsp; totQuery = "%s '%s' OR" %(begQuery,rec)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print totQuery
&amp;nbsp;&amp;nbsp;&amp;nbsp; query.append(totQuery)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
## Then if you need it all in one string
x = ' '.join(str(s) for s in query)
print x


&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course apply it to your stuff the output it gives me is&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab1' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab2' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab3' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab4' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"LOT_PLAN" =&amp;nbsp; 'ab1' OR "LOT_PLAN" =&amp;nbsp; 'ab2' OR "LOT_PLAN" =&amp;nbsp; 'ab3' OR "LOT_PLAN" =&amp;nbsp; 'ab4' OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At the end you would need to cut off the OR or have a differnt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;variable or some sort of catch that if its the end of the record count use that&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helped&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:37:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715105#M2365</guid>
      <dc:creator>LindseyWood</dc:creator>
      <dc:date>2021-12-12T06:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715106#M2366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: curtvprice&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for that. I put your code in and run it, but it still comes up the same result.&lt;BR /&gt;Here is the updated code:Any idea?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes - when you read records that way, the newline "\n" is included in rec.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; f = open("log")
&amp;gt;&amp;gt;&amp;gt; for rec in f:
...&amp;nbsp;&amp;nbsp; rec
...
'201211291133&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0cprice ap\n'
'201211291133&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0cprice ae\n'
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suggest using the .strip() string function to remove whitespace around your text record, including newline:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for rec in f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; queries.append(qry.format(rec.strip()))
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:37:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715106#M2366</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T06:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query string in Python</title>
      <link>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715107#M2367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for that, the strip() function does work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the updated script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;f_count = open("C:\GeoSpatialTraining\ArcGIS10\GISProgramming101\Exercises\Data\Local data\LotPlan_List.txt", "r")
#Count records number
numRec = len(f_count.readlines())
print "There are " + str(numRec) + " records in the file."

f = open("C:\GeoSpatialTraining\ArcGIS10\GISProgramming101\Exercises\Data\Local data\LotPlan_List.txt", "r")
sQuery = ""
i = 0

for rec in f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print rec
&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i &amp;lt; numRec:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sQuery = sQuery + "\"LOT_PLAN\" = '" + rec.strip() + "' OR " 
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sQuery = sQuery + "\"LOT_PLAN\" = '" + rec.strip() + "' "
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print sQuery
f.close()
print sQuery&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:37:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/build-a-query-string-in-python/m-p/715107#M2367</guid>
      <dc:creator>TerenceChen</dc:creator>
      <dc:date>2021-12-12T06:37:32Z</dc:date>
    </item>
  </channel>
</rss>

