<?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: Create variable with Cursor and write it in a text file with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167352#M12925</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Luke i am getting a&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Runtime error Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "", line 12, in RuntimeError: A column was specified that does not exist.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but i cannot understand why&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 May 2015 19:32:33 GMT</pubDate>
    <dc:creator>KONPETROV</dc:creator>
    <dc:date>2015-05-28T19:32:33Z</dc:date>
    <item>
      <title>Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167349#M12922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, i am trying to create three variables from a table and write them in a text file with Python. These variables are values from the first row of three fields. I tried it with Search Cursor but i can get only the first variable, i don't know why. Next i am trying to do the same with a folder of polylines taking the first row of 2 fields using the same text i created above but unsuccesfully. Any suggestion would be great. Thanks a lot. This is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os
from arcpy import env

&lt;SPAN style="line-height: 1.5;"&gt;arcpy.env.workspace = "c:/Win/Sik"&lt;/SPAN&gt;
input = "s3s2c10"
fields = ['X', 'Y', 'MOSAIC']

#NEW TXT FILE "MOON"
outFile = open("c:/Win/Sik/moon.text", "w")
with arcpy.da.SearchCursor(input, fields, 'OID = 1') as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; X = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; Y = row[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; IPSOS = row[2]

outFile.write('x is '+str(X)+'meters,'\n' Y is'+str(Y)+'and '\n' ipsos is'+str(IPSOS))
outfile.close()

import arcpy
import os
arcpy.env.workspace = "c:Win/Sik/True
outFile = open("c:/Win/Sik/moon.text", "w")
featureclasses = arcpy.ListFeatureClasses("Truelines", "Polyline", "")
for fc in featureclasses:
&amp;nbsp;&amp;nbsp;&amp;nbsp; TIME = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; DISTANCE = row[1] 
outFile.write( '\n''\n' 'TIME is '+str(TIME)+'meters,'\n' and DISTANCE is'+str(DISTANCE)+'meters'
outfile.close()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167349#M12922</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2021-12-11T08:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167350#M12923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For the 1st part (and the 2nd but well get to that later), you dont define 'row' anywhere, so I dont know where its getting the variable from!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To correct try adding the line 'for row in cursor:' as I have below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os
from arcpy import env

arcpy.env.workspace = "c:/Win/Sik"
input = "s3s2c10"
fields = ['X', 'Y', 'MOSAIC']

#NEW TXT FILE "MOON"
outFile = open("c:/Win/Sik/moon.text", "w")
with arcpy.da.SearchCursor(input, fields, 'OID = 1') as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; X = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y = row[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPSOS = row[2]

outFile.write('x is '+str(X)+'meters,'\n' Y is'+str(Y)+'and '\n' ipsos is'+str(IPSOS))
outfile.close()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167350#M12923</guid>
      <dc:creator>LukeWebb</dc:creator>
      <dc:date>2021-12-11T08:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167351#M12924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kon,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your search cursor, try the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(input, fields, 'OID = 1') as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; X = row[0] 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y = row[1] 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPSOS = row[2]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the folder of polyline feature classes, if there are many feature classes you are trying to iterate through, you will want to use a wildcard.&amp;nbsp; You existing syntax will only find a feature class called 'Truelines'.&amp;nbsp; You may want to add try '*'.&amp;nbsp; This will iterate through all of the feature classes in the workspace.&amp;nbsp; Ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;featureclasses = arcpy.ListFeatureClasses("*", "Polyline", "")&amp;nbsp; 
for fc in featureclasses:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TIME = row[0]&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DISTANCE = row[1]&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; outFile.write( '\n''\n' 'TIME is '+str(TIME)+'meters,'\n' and DISTANCE is'+str(DISTANCE)+'meters'&amp;nbsp; 
outfile.close() &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167351#M12924</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T08:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167352#M12925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Luke i am getting a&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Runtime error Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "", line 12, in RuntimeError: A column was specified that does not exist.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but i cannot understand why&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 19:32:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167352#M12925</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-28T19:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167353#M12926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jake with the first block i am getting the same error as in Luke:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Runtime error Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "", line 12, in RuntimeError: A column was specified that does not exist.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the second block of code, "Trueline" is my wildcard. And i have&amp;nbsp; ap problem with the last line cause&amp;nbsp; i am getting an error &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Parsing error SyntaxError: invalid syntax (line 12)&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 19:58:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167353#M12926</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-28T19:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167354#M12927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check that your input shapefile indeed has a field called 'OID' and not the more usual 'FID' field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Compare:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = r"C:\junk"
... input = "points"
... fields = ['heading','distance']
... with arcpy.da.SearchCursor(input,fields,"OID = 1") as cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 5, in &amp;lt;module&amp;gt;
RuntimeError: A column was specified that does not exist.
&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = r"C:\junk"
... input = "points"
... fields = ['heading','distance']
... with arcpy.da.SearchCursor(input,fields,"FID = 1") as cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
(192, 533)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167354#M12927</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T08:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167355#M12928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Οh, god. Yes you are right about that,&amp;nbsp; table has a Rowid starting from 1 and Polyline an FID starting from 0. But i am still getting an error &lt;SPAN style="text-decoration: underline;"&gt;Parsing error SyntaxError: unexpected character after line continuation character (line 17)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;when i run it inside outfile to write it in my text.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 20:53:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167355#M12928</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-28T20:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167356#M12929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;I don't believe you need all the quotes around the \n's:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14328466176072797 jive_text_macro" data-renderedposition="47_8_912_16" jivemacro_uid="_14328466176072797"&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;outFile.write(&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;'x is ' + str(X) + 'meters,\n Y is' + str(Y) + 'and \n ipsos is' &lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;+ str(IPSOS))&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 20:57:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167356#M12929</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-05-28T20:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167357#M12930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;and of course you were right again! I have two last questions, can i have these two scripts together as a tool because these are two different workspaces.? How can i pass also the name of each shp ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 21:48:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167357#M12930</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-28T21:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167358#M12931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To pass in the names of the shapefiles you can use &lt;EM&gt;arcpy.GetParameterAsText()&lt;/EM&gt;. For an outline of how to do this see these pages:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Setting_script_tool_parameters/00150000000n000000/"&gt;Setting script tool parameters&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Accessing_parameters_in_a_script_tool/001500000007000000/"&gt;Accessing parameters in a script tool&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using parameters you could also pass in the different workspaces and switch between them when required.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 22:07:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167358#M12931</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2015-05-28T22:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167359#M12932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Owen. It's just that i haven't used again two different workspaces inside a script.&lt;/P&gt;&lt;P&gt;Except from that for the iteration of shapefiles this is the code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy&amp;nbsp; 
import os
from arcpy import env
arcpy.env.workspace = "c:Win/Sik/Routes"&amp;nbsp; 
outFile = open("c:/Win/Sik/moon.text", "w")&amp;nbsp; 
featureclasses = arcpy.ListFeatureClasses("RT", "Polyline", "")
for fc in featureclasses:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ['DISTANCE', 'DURATION']
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields, "FID = 0") as cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TIME = row[0]&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; DISTANCE = row[1]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
outFile.write('TIME is ' + str(TIME) + 'meters,\n Y is' + str(DISTANCE) + 'and \n ipsos is' + str(DISTANCE))&amp;nbsp;&amp;nbsp;&amp;nbsp; 
outfile.close()&lt;/PRE&gt;&lt;P&gt;but i get back that error&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;STRONG style="color: #e23d39;"&gt;Runtime error&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;STRONG style="color: #e23d39;"&gt;Traceback (most recent call last):&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;STRONG style="color: #e23d39;"&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 7, in &amp;lt;module&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;STRONG style="color: #e23d39;"&gt;TypeError: 'NoneType' object is not iterable&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;although i have defined the type of shapefiles&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167359#M12932</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2021-12-11T08:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167360#M12933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What does is it mean, "is not iterable"? How can that be?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 22:45:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167360#M12933</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-28T22:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167361#M12934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the arcpy.ListFeatureClasses command is returning None (which is not iterable) because the workspace is not getting set correctly in line 4.&amp;nbsp; Try updating line 4 to:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14328553213715673 jive_text_macro" data-renderedposition="50_8_912_16" jivemacro_uid="_14328553213715673" modifiedtitle="true"&gt;&lt;P&gt;arcpy.env.workspace = &lt;SPAN class="string"&gt;"c:/Win/Sik/Routes"&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 23:22:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167361#M12934</guid>
      <dc:creator>BillDaigle</dc:creator>
      <dc:date>2015-05-28T23:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167362#M12935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i did it already Daigle, but still remains. I also applied this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy&amp;nbsp; 
... import os
... from arcpy import env
... arcpy.env.workspace = "c:/Win/Sik/Routes"&amp;nbsp; 
... outFile = open("c:/Win/Sik/moon.text", "w")&amp;nbsp; 
... featureclasses = arcpy.ListFeatureClasses("RT", "Polyline")
... for fc in featureclasses:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ['DISTANCE', 'DURATION']
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields, "FID = 0") as cursor:&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write('distance is ' + str(row[0]) + 'meters,\n duration is' + str(row[1])
... outFile.close()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but either it returns nothing or overwrites the previous results from text file leaving an empty file&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167362#M12935</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2021-12-11T08:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167363#M12936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think i found it! The wildcard(*) for God. Now can i put these to scripts to be together as one or the second will overwrite the first?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="104513" alt="mm.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/104513_mm.png" style="width: 620px; height: 349px;" /&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 May 2015 01:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167363#M12936</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-29T01:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable with Cursor and write it in a text file with Python</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167364#M12937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Two issues with OID = 1 worth noting I think:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. You can get the name o the object ID field (which can vary by data source and sometimes by workflow) you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;OIDField&amp;nbsp; = arcpy.Describe(lyr).OIDFieldName&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. The first row can be object ID zero or one, depending on data source. If what you want the first row, I'd do this instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;row = arcpy.da.SearchCursor(input, fields).next()
print row&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-with-cursor-and-write-it-in-a-text/m-p/167364#M12937</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T08:43:39Z</dc:date>
    </item>
  </channel>
</rss>

