<?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: Error using SearchCursor to export values to text file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530927#M41567</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The first error message is telling you what's wrong. You trying to use a variable materialType, but haven't defined it. You first need a statement like materialType = 'plastic'. I'm also not sure you should have the % sign right next to the variable name - % materialType instead of %materialType. Maybe that's ok.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You may want to consider the more recent method of formatting strings:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Qry = "Material = {0}".format(materialType)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Jun 2014 16:56:42 GMT</pubDate>
    <dc:creator>Zeke</dc:creator>
    <dc:date>2014-06-13T16:56:42Z</dc:date>
    <item>
      <title>Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530926#M41566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have created a very basic script (with the help of others) that uses a searchCursor to pull data from a feature class and, in theory, add that data to a text file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I almost have it but I am still getting a few errors that I cannot figure out (I am completely new to python and am at a complete loss now).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first error I get is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "G:\Olson-Murphy_Week10\Scripts\MaterialSearch2.py", line 10, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Qry = "Material = " + '%s' %materialType&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NameError: name 'materialType' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (MaterialReport).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By removing "%materialType" from the script i get this error to go away but then I am faced with another:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "G:\Olson-Murphy_Week10\Scripts\MaterialSearch2.py", line 14, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; MaterialSearch = arcpy.SearchCursor(fc,Qry, fields = "Material;Diameter;System")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\__init__.py", line 1133, in SearchCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; return gp.searchCursor(dataset, where_clause, spatial_reference, fields, sort_fields)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 359, in searchCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; self._gp.SearchCursor(*gp_fixargs(args, True)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (MaterialReport).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code can be found below. Anyone have any suggestions? (this code someone else did say worked on their machine so I am at a total loss)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
# Set workspace
arcpy.env.workspace = r"G:\Olson-Murphy_Week10\SouthFloridaNaturalGas.gdb"


#Estabslish input feature class
fc = r"G:\Olson-Murphy_Week10\SouthFloridaNaturalGas.gdb\Mains"

# Establish materials search for tool
Qry = "Material = " + '%s' %materialType


# Create cursor to search gas mains by material
MaterialSearch = arcpy.SearchCursor(fc,Qry, fields = "Material;Diameter;System")

#Define output
outReport = arcpy.GetParameterAsText(1)

#Open the report text file in write mode
file = open (outReport, "w")

#Add Header lines to report text file
file.write("Mains found in this report include:\n")
file.write("Material:" + Qry + "\n")

#Results of SearchCursor
for row in MaterialSearch:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptMat = str(row.getValue("Material"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptDiam = str(row.getValue("Diameter"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptSys = str(row.getValue("System"))

&amp;nbsp;&amp;nbsp;&amp;nbsp; file.write(rptMat + " " + rptDiam + " " + rptSys + "\n")

del MaterialSearch, row
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530926#M41566</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2021-12-12T16:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530927#M41567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The first error message is telling you what's wrong. You trying to use a variable materialType, but haven't defined it. You first need a statement like materialType = 'plastic'. I'm also not sure you should have the % sign right next to the variable name - % materialType instead of %materialType. Maybe that's ok.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You may want to consider the more recent method of formatting strings:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Qry = "Material = {0}".format(materialType)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 16:56:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530927#M41567</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-06-13T16:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530928#M41568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The first error message is telling you what's wrong. You trying to use a variable materialType, but haven't defined it. You first need a statement like materialType = 'plastic'. I'm also not sure you should have the % sign right next to the variable name - % materialType instead of %materialType. Maybe that's ok.&lt;BR /&gt;&lt;BR /&gt;You may want to consider the more recent method of formatting strings:&lt;BR /&gt;Qry = "Material = {0}".format(materialType)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for the other option of formatting. I think i like that better!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The way I have to took working I have it so you select the material type you want, its not something I want hard-coded into the scripit. That is what I am trying to to do with that bit of script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With your formatting string I updated it so I &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;think&lt;/SPAN&gt;&lt;SPAN&gt; it should allow me to set the variable in the tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Qry = "Material = {0}".format(arcpy.GetParameterAsText(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; but I still get that second error posted above. Any ideas on what that one is? (I have been looking for this answer for a few days so any ideas would be greatly appreciated!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 17:07:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530928#M41568</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2014-06-13T17:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530929#M41569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Esther&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Out of curiousity are what version of ArcGIS are you on?&amp;nbsp; If you are on 10.1 or higher I would highly recommend using the arcpy.da.SearchCursor, since they are faster and the inputs are a little easier to use.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When using the old style cursors, the fields are the 4th parameter, not the third. so you would need a placeholder string between the query and your fields.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Secondly, the issue is your made your field parameter fields =&amp;nbsp; "Material;Diameter;System"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is likely what is causing it to crash, I would either declare the fields to a variable called fields before the cursor or just hard code the fields names in the cursor.&amp;nbsp; Its looking for a string value, whereas you are making a variable there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.SearchCursor(fc,Qry, "",&amp;nbsp; "Material; Diameter; System")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;alternatively:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fields = "Material; Diameter; System"
arcpy.SearchCursor(fc,Qry, "",&amp;nbsp; fields)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:07:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530929#M41569</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-11T23:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530930#M41570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ian,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for this information. Since I am using 10.1 I will have to look at acrpy.da.SeachCursor to see if that makes more sense to me. Unfortunately this is&amp;nbsp; school assignment, due Sunday AM so I don't have much time to figure it out (plus, sadly, I have already been looking at this for a week!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, than you for the alternatives for seachCursor in terms of how I was identifying the fields to. Unfortunately, after trying both yours suggestions I still got the same error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you again for help and any other suggestions!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Esther&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 17:41:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530930#M41570</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2014-06-13T17:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530931#M41571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try printing Qry right after you set it to make sure it has the value you want. Maybe print other values as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For Get ParameterByText to work, you need to have made the script a tool, or run it from the command line with arguments. I recommend hard coding some values in for testing. Once it works there, you can switch to parameters.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 18:08:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530931#M41571</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-06-13T18:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530932#M41572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try printing Qry right after you set it to make sure it has the value you want. Maybe print other values as well.&lt;BR /&gt;&lt;BR /&gt;For Get ParameterByText to work, you need to have made the script a tool, or run it from the command line with arguments. I recommend hard coding some values in for testing. Once it works there, you can switch to parameters.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for reminding me to do this. I have been testing it as a tool (since that is my ultimate goal) but hard coding it is a good idea so I tried that, but now I am getting a syntax error that I cannot figure out. Here is the 'new' code.... syntax Error is associated with #Establish material search for tool: Qry is invalid syntax.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
# Set workspace
arcpy.env.workspace = r"G:\Olson-Murphy_Week10\SouthFloridaNaturalGas.gdb"


#Estabslish input feature class
fc = r"G:\Olson-Murphy_Week10\SouthFloridaNaturalGas.gdb\Mains"

# Establish Class fields
Field = ["Material", "Diameter", "System]"

# Establish materials search for tool
Qry ="Material = Plastic"

# Establish Class fields
Field = ["Material", "Diameter", "System]"

#Define output
outReport = arcpy.GetParameterAsText(1)

#Open the report text file in write mode
file = open (outReport, "w")

#Add Header lines to report text file
file.write("Mains found in this report include:\n")
file.write("Material:" + Qry + "\n")

# Create cursor to search gas mains by material
arcpy.da.SearchCursor(fc,Qry, fields) as Qry:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in Qry:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptMat = str(row.getValue("Material"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptDiam = str(row.getValue("Diameter"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptSys = str(row.getValue("System"))

&amp;nbsp;&amp;nbsp;&amp;nbsp; file.write(rptMat + " " + rptDiam + " " + rptSys + "\n")

del Qry, row

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:07:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530932#M41572</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2021-12-11T23:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530933#M41573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Query expressions can be a bit annoying to put into a python script, especially if you have to store them as a string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

Qry ="'Material' = \"Plastic\""

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Check this &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/00s5/00s50000002t000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;link&lt;/A&gt;&lt;SPAN&gt; for more help on building query expressions&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:07:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530933#M41573</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-11T23:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530934#M41574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;try&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

Qry ="'Material' = \"Plastic\""

&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Tried this but still have the same syntax error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;exceptions.SyntaxError:invalid syntax (line 13, offset 3) 'Qry ="'Material' = \"Plastic\""'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After all the time I have spent looking at this I have a feeling its a mix of mass confusion on my part and total rookie mistakes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have managed to get similar codes to work not as tools, but simply printing the results, but for some reason this one is really fighting me!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for all the help. As you can tell I'm a little lost and frustrated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:07:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530934#M41574</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2021-12-11T23:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530935#M41575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I see you switched over to arcpy.da.cursor, and that is part of what is causing the new issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.da.SearchCursor(fc,Qry, fields) as Qry:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;first parameters is your fc, second parameter is fields (as a list, which you did, great job!), third parameter is the where clause&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so it should be &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

with arcpy.da.SearchCursor(fc, fields, Qry) as cursor:&amp;nbsp; """(you don't want to use Qry, since that variable is already declared) """
&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptMat = str(row.getValue("Material"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptDiam = str(row.getValue("Diameter"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptSys = str(row.getValue("System"))

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just finished my first python class last semester, and it frustrated a good half of the class alot, especially since almost none of us had a CS background.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: Greg I noticed that extra quotation as well, but I figured she had already gotten past that syntax error, with the error code she was throwing&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530935#M41575</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-11T23:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530936#M41576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ian fixed it, but also notice that when you set the SearchCursor, you forgot the with keyword.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure why you set Field twice, but no harm done. Except you have the last quotation mark outside the closing list bracket.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 19:18:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530936#M41576</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-06-13T19:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530937#M41577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Ian!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Things seem to be working better now&amp;nbsp; (and I saw the missing&amp;nbsp; keyword too &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; )... and I figured out the syntax error as well (brackets in the wrong place!).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, though, another error! (shocking &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp; )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This time I am getting with my SearchCursor. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"RuntimeError: cannot open 'G:\Olson-Murphy_Week10\SouthFloridaNaturalGas.gdb\Mains"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have copied this location out of arcCatalog so I know its not&amp;nbsp; location issue. I also removed the '-' and '_' and re-pathed everything to make sure that was not the issue.... I'm going to keep fighting with it but any more ideas?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope all you pros are having fun picking apart this easy little script &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 19:25:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530937#M41577</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2014-06-13T19:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530938#M41578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure this is it, but in the error code it threw, it shows a single quote starting your file location and no single quote ending it.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, the file is just a fc in the gdb, not within a feature dataset or anything, if it is, you need to add the feature dataset to your file path.&amp;nbsp; You shouldn't need to hard code the file path, since you set your environment, it will automatically check that location for the file, so you could do fc = "Mains", though for the sake of this particular script I'd leave it alone til it is working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Make sure you don't have the file Mains open in ArcCatalog or ArcGIS, it will have a lock on it making you unable to access it with the cursor(I think).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: Haha, yes always lots of error codes.&amp;nbsp; I always get tons&amp;nbsp; of them on scripts I write, but it feels to much better by the time works right.&amp;nbsp; For future reference, I'd write small parts of code at a time, debugging each section as I go.&amp;nbsp; Once you get one section working, move to the next, it makes it easier to handle errors, and you get small victories as you go, instead of a pile of possible errors at the end.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 19:35:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530938#M41578</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-06-13T19:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530939#M41579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you everyone for the help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I wish I had time time (and skill) to do this in steps to make sure everything worked before moving on but, alas, I do not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still getting the same RuntimeError: Cannot Open "Feature Class" and am unsure why. I have tried double quote, single quotes, full path, just the feature class name, and changed the capitalization still without any luck.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is what I am working with. If anyone is REALLY bored and wants data to play with let me know:) ... or if you just see some glaring errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At least I am ahead of where I was before.... now at least the header end up in the text time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for all the help&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r"E:\OlsonMurphyWeek10\SouthFloridaNaturalGas.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Estabslish input feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fc = r"E:\OlsonMurphyWeek10\SouthFloridaNaturalGas.gdb\Mains"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Establish Class fields&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fields = ["Material", "Diameter", "System"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Establish materials search for tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Qry ="'Material' = \"Plastic\""&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Define output&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outReport = r"E:\OlsonMurphyWeek10\Outputs\Report.txt"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Open the report text file in write mode&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file = open (outReport, "w")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Add Header lines to report text file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file.write("South FLorida Distrbution Mains:\n")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file.write("Material:" + Qry + "\n")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create cursor to search gas mains by material&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;with arcpy.da.SearchCursor(fc, fields, Qry) as cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rptMat = str(row.getValue("Material"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rptDiam = str(row.getValue("Diameter"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rptSys = str(row.getValue("System"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file.write(rptMat + " " + rptDiam + " " + rptSys + "\n")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;del cursor, row&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[\CODE]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 23:09:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530939#M41579</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2014-06-13T23:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530940#M41580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about you post your code and data (or a sample), and I'll try to look at it this weekend. Its Fathers day weekend, so can't promise your Sunday deadline, but will try if possible.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 00:56:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530940#M41580</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-06-14T00:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530941#M41581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;How about you post your code and data (or a sample), and I'll try to look at it this weekend. Its Fathers day weekend, so can't promise your Sunday deadline, but will try if possible.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you so much! that would be great.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just make sure you don't miss out on Father's Day weekend... its an important one!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attached a zip folder with my data and script. Its all dummy data I made up for the project so its very basic, and there isn't a lot of it &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Again&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Esther&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 01:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530941#M41581</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2014-06-14T01:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530942#M41582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to thank everyone again for all the help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;While I may not manage to get this script tool to work for this week's due date, I do hope to use it for a project I am doing for class as well as for work so I am still working at it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That being said, does anyone know why I would get the error that my feature class cannot be opened? Would this be different than not being able to locate the feature class? As far as I can tell it is not locked and it not opened anywhere accept for in the MXD I am working with. So confused!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Esther&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 23:27:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530942#M41582</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2014-06-14T23:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530943#M41583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Esther,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry if this is too late for your deadline, had a busy weekend. I've tried several variations of the script below, which as far as I can see should work, but also getting the can't open error. I'm starting to think it's a problem because (at home) I'm on 10.2, but the data was created in 10.2.1 or 10.2.2, except I see it fine in ArcCatalog. Can't export it, though, so no help there. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What version of Arc are you using? Another possibility is that the gdb or data got corrupted somehow. Can you get a fresh copy? You did a good job setting it up as a tool, so kudos there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;edit: oh, also, wouldn't use 'Expression' with an upper case e, since that comes up as an existing word in intellisense.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = r"C:\Test\OlsonMurphyWeek10\SouthFloridaNaturalGas.gdb\Mains"
classField = "Material"
fields = ["Material", "Diameter", "System"]
expression = arcpy.AddFieldDelimiters(fc, classField) + " = 'Plastic'"

#Define output
##outReport = arcpy.GetParameterAsText(1)
outReport = r"C:\Test\Esther.txt"

#Open the report text file in write mode
with open(outReport, "w") as rptFile:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add Header lines to report text file
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptFile.write("Mains found in this report include:\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; rptFile.write(expression + "\n")
print fc
print fields
print expression
# Create cursor to search gas mains by material
with arcpy.da.SearchCursor(fc, fields, expression) 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; rptMat = str(row.getValue("Material"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rptDiam = str(row.getValue("Diameter"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rptSys = str(row.getValue("System"))

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rptFile.write(rptMat + " " + rptDiam + " " + rptSys + "\n")

print "Done!"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:07:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530943#M41583</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2021-12-11T23:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error using SearchCursor to export values to text file</title>
      <link>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530944#M41584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for taking another look at it. While it is a bit frustrating that it doesn't seem to be working i do feel a bit better that, perhaps, it is not me!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will try to re-create the gdb. Unfortunately I created the data on my own and, stupidly, did not create a back up for it (oh retrospect!). If my new gdb doesn't work i can just recreated the data and try again. I would rather not but it really doesn't take too long to so and, if it means success, I'm game!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you again for taking your time to take a look!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Esther&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2014 16:16:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-using-searchcursor-to-export-values-to-text/m-p/530944#M41584</guid>
      <dc:creator>EstherOlson-Murphy</dc:creator>
      <dc:date>2014-06-17T16:16:56Z</dc:date>
    </item>
  </channel>
</rss>

