<?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: Script to contatenate the same field from several records in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453382#M35581</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Even more pythonic! Except I don't know how to format as code on the new forums here...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;with open(r'H:\Documents\blah\'output.txt', 'w') as fout:&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; values = np.genfromtxt(r'H:\Documents\blah\input.txt',dtype='str')&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fout writelines("ID='" + str(val) + "' OR " for val in values)&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, for your output, rather than a bunch of OR clauses, you could make a python list and test using IN:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID IN ['34012', 35078', '39222'...]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Sep 2014 17:28:39 GMT</pubDate>
    <dc:creator>Zeke</dc:creator>
    <dc:date>2014-09-26T17:28:39Z</dc:date>
    <item>
      <title>Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453374#M35573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for a script, preferably a Python script that reads all the records from a file and concatenates them in a result variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using ArcMap to "Select By Attributes" and I would like to have a way to format a list of IDs I am importing form a text file, or Ms Excell list. To build a Definition Query in the Query Builder window.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM style="text-decoration: underline;"&gt;Input: (from xxx.txt)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;341440&lt;/P&gt;&lt;P&gt;341444&lt;/P&gt;&lt;P&gt;341521&lt;/P&gt;&lt;P&gt;341534&lt;/P&gt;&lt;P&gt;341580&lt;/P&gt;&lt;P&gt;341664&lt;/P&gt;&lt;P&gt;341783&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM style="text-decoration: underline;"&gt;Output: (to zzz.txt)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID=’341440’ OR ID= ‘341444’ OR ID= ‘341521’ OR ID= ‘341534’ OR ID= ‘341580’ OR ID= ‘341664’ OR ID= ‘341783’&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 12:37:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453374#M35573</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2014-09-26T12:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453375#M35574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So you have 1 field with numbers such as 341423 and you want it to be ID = 341423?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could field calculate using python.&amp;nbsp; This will calculate every record and add ID = in front of all the numbers.&amp;nbsp; Be sure that your field is a String/Text field.&amp;nbsp; ArcMap may import it in as an integer or double field.&amp;nbsp; I would create a new field and field calculate that one so you don't accidentally type something in wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'ID = ' + !field!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 12:47:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453375#M35574</guid>
      <dc:creator>StevenGraf1</dc:creator>
      <dc:date>2014-09-26T12:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453376#M35575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;how do you build the result string:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result = "ID=’341440’ OR ID= ‘341444’ OR ID= ‘341521’ OR ID= ‘341534’ OR ID= ‘341580’ OR ID= ‘341664’ OR ID= ‘341783’"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 12:51:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453376#M35575</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2014-09-26T12:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453377#M35576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In python, you can open and read/write a file using..&lt;/P&gt;&lt;P&gt;&lt;SPAN class="gp"&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="n"&gt;f&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="nb"&gt;open&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'your file - full path here'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'r'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;You can also open it for writing using..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="p"&gt;f = open('your file', 'w')&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="p"&gt;f.write("your text")&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;For your situation you might want to do this in a script (I am just giving you the overview)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;1. Open the File&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;2. Read each line and concatenate the results to build your select query&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; using this after you open it..&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="k"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;for&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;SPAN class="n"&gt;line&lt;/SPAN&gt; &lt;SPAN class="ow"&gt;in&lt;/SPAN&gt; &lt;SPAN class="n"&gt;f&lt;/SPAN&gt;&lt;SPAN class="p"&gt;:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="go"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print line&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="go"&gt;3. &lt;/SPAN&gt;&lt;SPAN class="go"&gt;Print the concatenated results or store the result in another file using&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="go"&gt; f.write()&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="go"&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="go"&gt;*Note, you might want to write this as a python function so you can pass in the file to read from and the column name to use for your result query.&amp;nbsp; I am not sure exactly how you are trying to use this.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suggest you read this...&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2/tutorial/inputoutput.html" title="https://docs.python.org/2/tutorial/inputoutput.html"&gt;7. Input and Output — Python 2.7.8 documentation&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 13:50:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453377#M35576</guid>
      <dc:creator>IanGrasshoff</dc:creator>
      <dc:date>2014-09-26T13:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453378#M35577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a way using NumPy:&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: Consolas;"&gt;import numpy as np&lt;/SPAN&gt;


&lt;SPAN style="font-family: Consolas;"&gt;fout = open(r'H:\Documents\blah\output.txt', 'w')
values = np.genfromtxt(r'H:\Documents\blah\input.txt')
for val in values:
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: Consolas;"&gt;writevalue = "ID='" + str(val) + "' OR "&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fout.write(writevalue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
fout.close() &lt;/SPAN&gt;



&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:13:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453378#M35577</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T20:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453379#M35578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried to modify my original post but it won't let me because GeoNet is not a real forum. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/confused.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway... I noticed that the values will come convert over as decimal, which you may not want.&amp;nbsp; So, simply modify the genfromtxt() method to include the output format as strings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

values = np.genfromtxt(r'H:\Documents\blah\input.txt',dtype='str')

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the updated code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import numpy as np


fout = open(r'H:\Documents\blah\output.txt', 'w')
values = np.genfromtxt(r'H:\Documents\blah\input.txt',dtype='str')
for val in values:
&amp;nbsp;&amp;nbsp;&amp;nbsp; writevalue = "ID='" + str(val) + "' OR "
&amp;nbsp;&amp;nbsp;&amp;nbsp; fout.write(writevalue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print writevalue

fout.close()

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:13:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453379#M35578</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T20:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453380#M35579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/laugh.png" /&gt; Let's get a bit more pythonic and into just 4 lines:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1411746110777387 jive_text_macro" jivemacro_uid="_1411746110777387"&gt;
&lt;P&gt;fout = open(r'H:\Documents\blah\output.txt', 'w')&lt;/P&gt;
&lt;P&gt;values = np.genfromtxt(r'H:\Documents\blah\input.txt',dtype='str')&lt;/P&gt;
&lt;P&gt;fout.writelines("ID='" + str(val) + "' OR " for val in values)&lt;/P&gt;
&lt;P&gt;fout.close()&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 15:42:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453380#M35579</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-09-26T15:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453381#M35580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's how I do it. I have a function as this something I find myself doing a lot! This function works in 10.0 and 10.1. It reads a table, not a text file.&amp;nbsp; (If you add a field name to the top of your text file, and name the file with a .csv or .txt file extension you can read it directly as a table in ArcGIS.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14117504270825294" jivemacro_uid="_14117504270825294"&gt;
&lt;P&gt;def ListUnique(inTable, Field):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Create a list of unique values from a table/tableview.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arguments&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inTable&amp;nbsp; Table or table view&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Field&amp;nbsp;&amp;nbsp;&amp;nbsp; Field name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&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; # this will only work for 10.1&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; import arcpy.da&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; lstValues = [r[0] for r in&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.da.SearchCursor(inTable, Field)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except ImportError:&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; # 10.0 version&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; try:&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; Rows = arcpy.SearchCursor(inTable, "", "", Field, Field)&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; Row = Rows.next()&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; lstValues = []&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; while Row:&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstValues.append(Row.getValue(Field))&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Row = Rows.next()&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; except:&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; raise&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; finally:&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; del Row, Rows&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # unique-ize and sort the list&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstValues = sorted(set(lstValues))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return lstValues&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as msg:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception("ListUnique failed\n" + str(msg))&lt;/P&gt;








&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once you have the list of values, you can make this into a SQL expression from a list like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14117508672639811" jivemacro_uid="_14117508672639811"&gt;
&lt;P&gt;numlist = ",".join(str(L))&lt;/P&gt;
&lt;P&gt;strlist = ",".join(["'{}'".format(vv) for vv in L]) # need quotes for string values&lt;/P&gt;
&lt;P&gt;where = '"{}" IN ({})'.format(field, numlist) # "FIELD" IN (1,2,3)&lt;/P&gt;







&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;James wanted me to use the FIELD = 1 OR FIELD = 2 syntax, so here's a way to do that (this replaces line 03 above):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14120303855014018" jivemacro_uid="_14120303855014018"&gt;
&lt;P&gt;where = " OR ".join(['"{}" = {}'.format(field, k) for k in strlist])&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 16:54:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453381#M35580</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-09-26T16:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453382#M35581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Even more pythonic! Except I don't know how to format as code on the new forums here...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;with open(r'H:\Documents\blah\'output.txt', 'w') as fout:&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; values = np.genfromtxt(r'H:\Documents\blah\input.txt',dtype='str')&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fout writelines("ID='" + str(val) + "' OR " for val in values)&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, for your output, rather than a bunch of OR clauses, you could make a python list and test using IN:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID IN ['34012', 35078', '39222'...]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 17:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453382#M35581</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-09-26T17:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453383#M35582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;see &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;A href="https://community.esri.com/migration-blogpost/1070"&gt;Posting Code blocks in the new GeoNet&lt;/A&gt;‌&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 17:33:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453383#M35582</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-09-26T17:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453384#M35583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Curtis! I saw the &amp;gt;&amp;gt; icon, but hovering over it said Insert, which is not quite as intuitive as something like Format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 21:25:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453384#M35583</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-09-26T21:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453385#M35584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Keep in mind that the "IN" statement does have limits (depending upon database).&amp;nbsp; I think Oracle limit is 1000?&amp;nbsp; Not exactly sure but I recently had to break up my list of values that built my IN portion of a WHERE clause.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Sep 2014 18:02:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453385#M35584</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-09-29T18:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453386#M35585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not very familiar with "real" RDBMS's so I'm wondering what string length fails if you use the more basic form&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;FIELD = 1 OR FIELD = 2 or FIELD = 3 ...&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For 1000 fields that is at least 14K of text!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would guess that RDBMS would not support&amp;nbsp; indexes when you use the IN operator - but in theory that wouldn't be a problem with many in the list because IN would parallelize the comparisons (ie all comparisons would be done on each record, in one pass).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Sep 2014 22:32:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453386#M35585</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-09-29T22:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453387#M35586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Curtis,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In RDBMS-landia, if I have &amp;gt;1000 values I'd probably insert them into a temporary table of the values for my IN operator and setup a JOIN to the main table I am interested in querying.&amp;nbsp; I know that doesn't specifically address your post but is likely the best solution.&amp;nbsp; Or if I were in SQL Server I'd likely opt for the Table variable instead of a Temp Table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Sep 2014 12:38:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453387#M35586</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-09-30T12:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script to contatenate the same field from several records</title>
      <link>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453388#M35587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah - I've heard this type of join to select rows called a "filter".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There used be an awesome ARCPLOT command&amp;nbsp; that I still miss. (Those were the days.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;reselect &amp;lt;dataset&amp;gt; &amp;lt;dstype&amp;gt; keyfile &amp;lt;table&amp;gt; &amp;lt;field&amp;gt; keyitem &amp;lt;key_field&amp;gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried to reproduce this functionality using layers and the Add Join tool but found it slow and unreliable.&lt;/P&gt;&lt;P&gt;Maybe the Make Query tool... or a python solution using sets....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Oct 2014 00:52:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-contatenate-the-same-field-from-several/m-p/453388#M35587</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-01T00:52:27Z</dc:date>
    </item>
  </channel>
</rss>

