I need to remove forward slashes from the attributes in a layer. I need to remove the first \ and last \ and replace the double \\ with just one \. I would appreciate any help. Thanks.
Currently the attributes looks like this.
\R2\\M1\
\M1\\M1\\C2\
\AG\\R2\\M1\\R2\
I need it to look like the following
R2\M1
M1\M1\C2
AG\R2\M1\R2
I tried the following but got error "TypeError: argument of type 'NoneType' is not iterable" on line if '\\' if '\\' in row[0]: #if a double quote is in the string returned.
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"In_memory\LayerTest"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ZONING_CODE"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">'\\'</SPAN> <SPAN class="keyword token">in</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token">#if a double quote is in the string returned, </SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="operator token">=</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\\'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'\\'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#replace that double quote with an empty string (removes it) </SPAN>
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> row<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>