<?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: Python Error in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838218#M3425</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's your code using the formatting Dan refers to.&amp;nbsp; Clearly&amp;nbsp; the 'unexpected error' dosen't give you much to chew on, but you probably should look closely at the values of S1 and S2.&amp;nbsp; Using raw string on a quoted variable seems odd to me, but that's just me. See a suggested approach below...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy 
mxd &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MapDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;supports&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"DATASOURCE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"H:\GQRA_screening_tool\Shapefiles"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;lower&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dataSource&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;lower&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
            lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;findAndReplaceWorkspacePath&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"S1"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"S2"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
mxd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;saveACopy&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; mxd&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;S1_var &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'X:\path\to\never\never\land'&lt;/SPAN&gt;
S2_var &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'X:\path\to\greatness'&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;findAndReplaceWorkspacePath&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;S1_var&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; S2_var&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 10:11:56 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2021-12-12T10:11:56Z</dc:date>
    <item>
      <title>Python Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838215#M3422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Im receiving this error for a script that is trying to change selected string within a .shp file path.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestion on the error.&lt;A href="https://community.esri.com/t5/tag/arcpy/tg-p"&gt;#arcpy&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN&gt;Runtime error&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;File "&amp;lt;string&amp;gt;", line 6, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\utils.py", line 182, in fn_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return fn(*args, **kw)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\_mapping.py", line 697, in findAndReplaceWorkspacePath&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return convertArcObjectToPythonObject(self._arc_object.findAndReplaceWorkspacePath(*gp_fixargs((find_workspace_path, replace_workspace_path, validate), True)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ValueError: Layer: Unexpected error&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;For the following script.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import arcpy &lt;BR /&gt;... mxd = arcpy.mapping.MapDocument(r"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd") &lt;BR /&gt;... for lyr in arcpy.mapping.ListLayers(mxd): &lt;BR /&gt;... if lyr.supports("DATASOURCE"): &lt;BR /&gt;... if r"H:\GQRA_screening_tool\Shapefiles".lower() in lyr.dataSource.lower(): &lt;BR /&gt;... lyr.findAndReplaceWorkspacePath(r"S1", r"S2") &lt;BR /&gt;... mxd.saveACopy(r"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd") &lt;BR /&gt;... del mxd&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2019 10:15:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838215#M3422</guid>
      <dc:creator>AnthonyCorcoran1</dc:creator>
      <dc:date>2019-02-12T10:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838216#M3423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f6f6f6; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;(r"S1", r"S2")&amp;nbsp;&lt;/SPAN&gt; where are these defined? the full paths are needed&lt;/P&gt;&lt;P&gt;and I notice you have SI and S1 useage which may be a coincidence&lt;/P&gt;&lt;P&gt;Code formatting would help with indentation and provide line numbers as well&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2019 10:29:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838216#M3423</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-02-12T10:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838217#M3424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the "S1" and "S2" refer to section of around 200 .shp, im wanting to replace the S1 with S2 on all of them.&lt;/P&gt;&lt;P&gt;so i have it looking to the root folder where all these are stored.&amp;nbsp;&lt;SPAN&gt;H:\GQRA_screening_tool\Shapefiles&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;import arcpy &lt;BR /&gt;... mxd = arcpy.mapping.MapDocument(r"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd") &lt;BR /&gt;... for lyr in arcpy.mapping.ListLayers(mxd): &lt;BR /&gt;... &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if lyr.supports("DATASOURCE"): &lt;BR /&gt;... &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if r"H:\GQRA_screening_tool\Shapefiles".lower() in lyr.dataSource.lower(): &lt;BR /&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;lyr.findAndReplaceWorkspacePath(r"S1", r"S2") &lt;BR /&gt;... mxd.saveACopy(r"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd") &lt;BR /&gt;... del mxd&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2019 10:36:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838217#M3424</guid>
      <dc:creator>AnthonyCorcoran1</dc:creator>
      <dc:date>2019-02-12T10:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838218#M3425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's your code using the formatting Dan refers to.&amp;nbsp; Clearly&amp;nbsp; the 'unexpected error' dosen't give you much to chew on, but you probably should look closely at the values of S1 and S2.&amp;nbsp; Using raw string on a quoted variable seems odd to me, but that's just me. See a suggested approach below...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy 
mxd &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MapDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;supports&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"DATASOURCE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"H:\GQRA_screening_tool\Shapefiles"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;lower&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dataSource&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;lower&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
            lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;findAndReplaceWorkspacePath&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"S1"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"S2"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
mxd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;saveACopy&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"H:\GQRA_screening_tool\Arcmap\SwecoTemplate_SI_A3_S2.mxd"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; mxd&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;S1_var &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'X:\path\to\never\never\land'&lt;/SPAN&gt;
S2_var &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'X:\path\to\greatness'&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;findAndReplaceWorkspacePath&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;S1_var&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; S2_var&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:11:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838218#M3425</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-12T10:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838219#M3426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sharing with &lt;A href="https://community.esri.com/space/2145"&gt;Python&lt;/A&gt;‌ since this is an ArcPy question and not ArcGIS API for Python.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2019 17:17:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-error/m-p/838219#M3426</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-02-12T17:17:11Z</dc:date>
    </item>
  </channel>
</rss>

