<?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 using update cursor from python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171286#M13172</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi I am trying to update a field from File geodatabase using update cursor using where clause. but the search string has quote. I tried all different way to use where clause but did not work.&amp;nbsp; I really apprecaite if anyone can help me to solve this problem or work around.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;===============================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code that I am using from python win.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;===============================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;my_name = "New Horizon's place.JPG"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; where = Name =&amp;nbsp; '"%s"'&amp;nbsp; %my_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; cursor2 = arcpy.UpdateCursor(my_feature,where)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 1165, in UpdateCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return gp.updateCursor(dataset, where_clause, spatial_reference, fields, sort_fields)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 364, in updateCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self._gp.UpdateCursor(*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;SPAN&gt;An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used. [my_feature]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used. [SELECT * FROM my_feature WHERE ( "New Horizon's place.JPG" )]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 31 Jan 2014 11:40:32 GMT</pubDate>
    <dc:creator>ShakirAhmed1</dc:creator>
    <dc:date>2014-01-31T11:40:32Z</dc:date>
    <item>
      <title>using update cursor from python script</title>
      <link>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171286#M13172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi I am trying to update a field from File geodatabase using update cursor using where clause. but the search string has quote. I tried all different way to use where clause but did not work.&amp;nbsp; I really apprecaite if anyone can help me to solve this problem or work around.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;===============================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code that I am using from python win.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;===============================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;my_name = "New Horizon's place.JPG"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; where = Name =&amp;nbsp; '"%s"'&amp;nbsp; %my_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; cursor2 = arcpy.UpdateCursor(my_feature,where)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 1165, in UpdateCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return gp.updateCursor(dataset, where_clause, spatial_reference, fields, sort_fields)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 364, in updateCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self._gp.UpdateCursor(*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;SPAN&gt;An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used. [my_feature]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used. [SELECT * FROM my_feature WHERE ( "New Horizon's place.JPG" )]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 11:40:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171286#M13172</guid>
      <dc:creator>ShakirAhmed1</dc:creator>
      <dc:date>2014-01-31T11:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: using update cursor from python script</title>
      <link>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171287#M13173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Shakir,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The where statement is the problem. Can you explain exactly what you are trying to achieve with the where statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are a few things to note:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) A SQL (where) must be passed as a string (text) in python. This means it has to have quotes around it. You may also need to add some Backslashs (\) to quote marks. This tells python to use them only as a character and not defining the start/end of a string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) When building a SQL statement with wildcards ('%') you must use the 'LIKE' condition, not the '=' condition.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this out:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;my_feature = r"C:\Path\To\File.shp"
where = '\"Name\" LIKE \'%s\''&amp;nbsp;&amp;nbsp; #produces this: "Name" LIKE '%s'
cursor2 = arcpy.UpdateCursor(my_feature,where)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know how it goes. Good Luck!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;~Josh&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171287#M13173</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2021-12-11T08:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: using update cursor from python script</title>
      <link>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171288#M13174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello Shakir,&lt;BR /&gt;&lt;BR /&gt;The where statement is the problem. Can you explain exactly what you are trying to achieve with the where statement.&lt;BR /&gt;&lt;BR /&gt;Here are a few things to note:&lt;BR /&gt;1) A SQL (where) must be passed as a string (text) in python. This means it has to have quotes around it. You may also need to add some Backslashs (\) to quote marks. This tells python to use them only as a character and not defining the start/end of a string.&lt;BR /&gt;2) When building a SQL statement with wildcards ('%') you must use the 'LIKE' condition, not the '=' condition.&lt;BR /&gt;&lt;BR /&gt;Try this out:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
my_feature = r"C:\Path\To\File.shp"
where = '\"Name\" LIKE \'%s\''&amp;nbsp;&amp;nbsp; #produces this: "Name" LIKE '%s'
cursor2 = arcpy.UpdateCursor(my_feature,where)

&lt;/PRE&gt;&lt;BR /&gt;Let me know how it goes. Good Luck!&lt;BR /&gt;~Josh&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your reply but got following error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
my_name = "New Horizon's place.JPG"
my_feature = r"C:\Path\To\File.shp"
#where = '\"Name\" LIKE \'%s\''&amp;nbsp;&amp;nbsp; #produces this: "Name" LIKE '%s'
where = '\"Name\" LIKE \'%s\'' %my_name # here the my_name is the search string
cursor2 = arcpy.UpdateCursor(my_feature,where)

&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 1165, in UpdateCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return gp.updateCursor(dataset, where_clause, spatial_reference, fields, sort_fields)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 364, in updateCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self._gp.UpdateCursor(*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;SPAN&gt;An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used. [my_feature]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used. [SELECT * FROM my_feature WHERE ( "Name" LIKE 'New Horizon's place.JPG' )]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171288#M13174</guid>
      <dc:creator>ShakirAhmed1</dc:creator>
      <dc:date>2021-12-11T08:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: using update cursor from python script</title>
      <link>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171289#M13175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oh, sorry, I see it now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to replace any single quotes (') with &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;two single quotes&lt;/SPAN&gt;&lt;SPAN&gt; (''). This is how SQL understands single quotes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can manually change this in your script ("New Horizon's place.JPG" to "New Horizon''s place.JPG") or add a replace line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;my_name = "New Horizon's place.JPG"
my_name = my_name.replace("\'","\'\'")
my_feature = r"C:\Path\To\File.shp"
where = '\"Name\" LIKE \'%s\'' %my_name # here the my_name is the search string
cursor2 = arcpy.UpdateCursor(my_feature,where)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope it works!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171289#M13175</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2021-12-11T08:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: using update cursor from python script</title>
      <link>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171290#M13176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks&amp;nbsp; a lot Joshua Chisholm for your help. it worked.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 13:49:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-update-cursor-from-python-script/m-p/171290#M13176</guid>
      <dc:creator>ShakirAhmed1</dc:creator>
      <dc:date>2014-01-31T13:49:33Z</dc:date>
    </item>
  </channel>
</rss>

