I am having an issue with raw_input as a variable x. The user types the name and receives returned values. x is in the ly variable is not working.( Line 20) I know that I need to set this up slightly different but not sure how. (Line 22,23)
I can set the variable x as a hardcoded name and I get the correct results which confirms everything else is correct. (Line 21)
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
<SPAN class="comment token">#Set folder space</SPAN>
folder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'S:\\GIS\ServerMXDs\\_Future_Services\\CityWorks'</SPAN>
<SPAN class="keyword token">for</SPAN> filename <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>folder<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
fullpath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>folder<SPAN class="punctuation token">,</SPAN> filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>isfile<SPAN class="punctuation token">(</SPAN>fullpath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
basename<SPAN class="punctuation token">,</SPAN> extension <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>fullpath<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> extension<SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">".mxd"</SPAN><SPAN class="punctuation token">:</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>fullpath<SPAN class="punctuation token">)</SPAN>
dfs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> df <SPAN class="keyword token">in</SPAN> dfs<SPAN class="punctuation token">:</SPAN>
layers <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> df<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> layer <SPAN class="keyword token">in</SPAN> layers<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> layer<SPAN class="punctuation token">.</SPAN>isFeatureLayer<SPAN class="punctuation token">:</SPAN>
lyr_source <SPAN class="operator token">=</SPAN> layer<SPAN class="punctuation token">.</SPAN>dataSource
lyr_name <SPAN class="operator token">=</SPAN> layer<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"utf8"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"replace"</SPAN><SPAN class="punctuation token">)</SPAN>
ly <SPAN class="operator token">=</SPAN> lyr_source<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"utf8"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"replace"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">-</SPAN>
<SPAN class="comment token">#x = raw_input("type in feature name: ")</SPAN>
x <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ServiceEstablishments'</SPAN>
<SPAN class="keyword token">if</SPAN> x <SPAN class="keyword token">in</SPAN> str<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>ly<SPAN class="punctuation token">.</SPAN>split <SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\\'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> filename <SPAN class="operator token">+</SPAN> <SPAN class="string token">" "</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Service Name:"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" "</SPAN> <SPAN class="operator token">+</SPAN> df<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">+</SPAN> <SPAN class="string token">" "</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Layer Name:"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" "</SPAN> <SPAN class="operator token">+</SPAN> lyr_name<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>