<?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: GetParameterAsText() returning only one character in string in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134077#M10486</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Add an ArcPy AddMessage after var2 to see what exactly var2 is getting set to before you try to process it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 23 May 2020 14:13:30 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2020-05-23T14:13:30Z</dc:date>
    <item>
      <title>GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134070#M10479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I am a beginner and I have been experimenting with Python module in ArcGIS and I'm trying now to create some kind of automative map. I have set of .lyr files, geodatabase with shapefiles and .csv table with list of names of shapefiles in a row. My goal is to apply symbology to layers based on list picked from .csv table. Shapefiles in geodatabase and .lyr files are named accordingly. When I run hardcoded script, it works just fine. When I use arcpy.GetParameterAsText() troubles begin - the first paremeter dosn't seem to work well at all - it just collects the first character of string that I put in it while using script tool. Do you know, where is the problem?&lt;/P&gt;&lt;P&gt;error log:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "E:\Kursy_Michal\ArcGIS\Proby\Proba1\Symbologia_nocomment.py", line 30, in &amp;lt;module&amp;gt;&lt;BR /&gt; arcpy.MakeFeatureLayer_management(ob, fc)&lt;BR /&gt; File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\management.py", line 6986, in MakeFeatureLayer&lt;BR /&gt; raise e&lt;BR /&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000732: Input Features: Dataset E:\Kursy_Michal\ArcGIS\Proby\Proba1\Geobaza_1.gdb\l does not exist or is not supported&lt;BR /&gt;Failed to execute (MakeFeatureLayer).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Failed to execute (Script3).&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;code:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #cc7832;"&gt;import &lt;/SPAN&gt;arcpy
mxd = arcpy.mapping.MapDocument(&lt;SPAN style="color: #a5c261;"&gt;r"E:\Kursy_Michal\ArcGIS\Proby\Proba1\Proba1.mxd"&lt;/SPAN&gt;)
df = arcpy.mapping.ListDataFrames(mxd)[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
arcpy.env.workspace = &lt;SPAN style="color: #a5c261;"&gt;r'E:\Kursy_Michal\ArcGIS\Proby\Proba1\Geobaza_1.mdb'
&lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;import &lt;/SPAN&gt;csv

g = &lt;SPAN style="color: #8888c6;"&gt;globals&lt;/SPAN&gt;()
i = &lt;SPAN style="color: #6897bb;"&gt;0
&lt;/SPAN&gt;dct = {}

&lt;SPAN style="color: #cc7832;"&gt;with &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;open&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;'Warianty1.csv'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'r'&lt;/SPAN&gt;) &lt;SPAN style="color: #cc7832;"&gt;as &lt;/SPAN&gt;csvfile:
    reader = csv.reader(csvfile&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;delimiter&lt;/SPAN&gt;=&lt;SPAN style="color: #a5c261;"&gt;';'&lt;/SPAN&gt;)
    &lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;row &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;reader:
        dct[&lt;SPAN style="color: #a5c261;"&gt;'l_%s' &lt;/SPAN&gt;% i] = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#Creating dynamic lists named l_0, l_1, etc for each row
        g[&lt;SPAN style="color: #a5c261;"&gt;'l_{0}'&lt;/SPAN&gt;.format(i)] = row[:]
        i += &lt;SPAN style="color: #6897bb;"&gt;1
&lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;
#Choosing list by putting its' name to var2
&lt;/SPAN&gt;var2 = arcpy.GetParameterAsText(&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;)
#Delete empty values in list
&lt;SPAN style="color: #8888c6;"&gt;filter&lt;/SPAN&gt;(&lt;SPAN style="color: #8888c6;"&gt;None&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;eval&lt;/SPAN&gt;(var2))&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;path1 = arcpy.GetParameterAsText(&lt;SPAN style="color: #6897bb;"&gt;1&lt;/SPAN&gt;)

path2 = arcpy.GetParameterAsText(&lt;SPAN style="color: #6897bb;"&gt;2&lt;/SPAN&gt;)

#Giving symbology to layers created accordingly to names stored in list
&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;fc &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;eval&lt;/SPAN&gt;(var2):
     ob = path2 + &lt;SPAN style="color: #a5c261;"&gt;'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;\\&lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;' &lt;/SPAN&gt;+ fc
     arcpy.MakeFeatureLayer_management(ob&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;fc)
     arcpy.ApplySymbologyFromLayer_management(fc&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;path1 + &lt;SPAN style="color: #a5c261;"&gt;'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;\\&lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;' &lt;/SPAN&gt;+ fc + &lt;SPAN style="color: #a5c261;"&gt;'.lyr'&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:30:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134070#M10479</guid>
      <dc:creator>MichałKozłowski</dc:creator>
      <dc:date>2021-12-11T07:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134071#M10480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have been scripting with Python for years, and I seldom use eval, almost never.&amp;nbsp; Your use of it here caught my attention.&amp;nbsp; Can you explain what var2 looks like before you start manipulating it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, your filter line isn't doing what you think, but I will wait to comment on that until I see what you are trying to do with var2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2020 13:45:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134071#M10480</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-05-22T13:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134072#M10481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I declare var2 as parameter declared from script tool level. I want to var2 be a variable that stores name of list, that will be used in for loop (that is why I use eval - to iterate through the chosen list, not the var2 itself). In case I hardcode it (type var2 = 'l_1') then that loop is done correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When it comes to filter, previously I wanted to use while loop&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt; while '' in eval(var2):
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;     eval(var2).remove('')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;but it did not work&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:30:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134072#M10481</guid>
      <dc:creator>MichałKozłowski</dc:creator>
      <dc:date>2021-12-11T07:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134073#M10482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, I get what you are doing with eval, but this line isn't doing what you expect.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Delete empty values in list
&lt;SPAN style="color: #8888c6;"&gt;filter&lt;/SPAN&gt;(&lt;SPAN style="color: #8888c6;"&gt;None&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;eval&lt;/SPAN&gt;(var2))&lt;/PRE&gt;&lt;P&gt;In fact, this line isn't doing anything because calling filter returns a filter object that you haven't assigned to anything.&amp;nbsp; Filter does not work on the iterable in-place.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:30:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134073#M10482</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T07:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134074#M10483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, that's correct, my code looks now like this:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #cc7832;"&gt;import &lt;/SPAN&gt;arcpy
mxd = arcpy.mapping.MapDocument(&lt;SPAN style="color: #a5c261;"&gt;r"E:\Kursy_Michal\ArcGIS\Proby\Proba1\Proba1.mxd"&lt;/SPAN&gt;)
df = arcpy.mapping.ListDataFrames(mxd)[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
arcpy.env.workspace = &lt;SPAN style="color: #a5c261;"&gt;r'E:\Kursy_Michal\ArcGIS\Proby\Proba1\Geobaza_1.mdb'
&lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;import &lt;/SPAN&gt;csv

g = &lt;SPAN style="color: #8888c6;"&gt;globals&lt;/SPAN&gt;()
i = &lt;SPAN style="color: #6897bb;"&gt;0
&lt;/SPAN&gt;dct = {}

&lt;SPAN style="color: #cc7832;"&gt;with &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;open&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;'Warianty1.csv'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'r'&lt;/SPAN&gt;) &lt;SPAN style="color: #cc7832;"&gt;as &lt;/SPAN&gt;csvfile:
    reader = csv.reader(csvfile&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;delimiter&lt;/SPAN&gt;=&lt;SPAN style="color: #a5c261;"&gt;';'&lt;/SPAN&gt;)
    &lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;row &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;reader:
        dct[&lt;SPAN style="color: #a5c261;"&gt;'l_%s' &lt;/SPAN&gt;% i] = []
        g[&lt;SPAN style="color: #a5c261;"&gt;'l_{0}'&lt;/SPAN&gt;.format(i)] = row[:]
        i += &lt;SPAN style="color: #6897bb;"&gt;1
&lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;
&lt;/SPAN&gt;var2 = arcpy.GetParameterAsText(&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;)
var3 = &lt;SPAN style="color: #8888c6;"&gt;filter&lt;/SPAN&gt;(&lt;SPAN style="color: #8888c6;"&gt;None&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;eval&lt;/SPAN&gt;(var2))

path1 = arcpy.GetParameterAsText(&lt;SPAN style="color: #6897bb;"&gt;1&lt;/SPAN&gt;)

path2 = arcpy.GetParameterAsText(&lt;SPAN style="color: #6897bb;"&gt;2&lt;/SPAN&gt;)

&lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;fc &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;var3:
     ob = path2 + &lt;SPAN style="color: #a5c261;"&gt;'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;\\&lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;' &lt;/SPAN&gt;+ fc
     arcpy.MakeFeatureLayer_management(ob&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;fc)
     arcpy.ApplySymbologyFromLayer_management(fc&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;path1 + &lt;SPAN style="color: #a5c261;"&gt;'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;\\&lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;' &lt;/SPAN&gt;+ fc + &lt;SPAN style="color: #a5c261;"&gt;'.lyr'&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Error is still the very same as before. And, similarly, when I paste hardcoded version of this code into python console, it works fine, but when I use version with parameters as script tool, the error appears. Do you maybe know the reason behind this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:30:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134074#M10483</guid>
      <dc:creator>MichałKozłowski</dc:creator>
      <dc:date>2021-12-11T07:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134075#M10484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What type of script tool?&amp;nbsp; Did you define the parameters and their type using the script tool dialog after adding it to your toolbox?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2020 20:42:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134075#M10484</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-05-22T20:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134076#M10485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well... just simple script tool in my custom toolbox. And yes, I defined those parameters. You can take a look:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/493179_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2020 21:08:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134076#M10485</guid>
      <dc:creator>MichałKozłowski</dc:creator>
      <dc:date>2020-05-22T21:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134077#M10486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Add an ArcPy AddMessage after var2 to see what exactly var2 is getting set to before you try to process it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 May 2020 14:13:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134077#M10486</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-05-23T14:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: GetParameterAsText() returning only one character in string</title>
      <link>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134078#M10487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have finally worked this out. There appears that in this case you do not want to have quotes in arcpy.GetParameterAsText(). Putting l_1 instead of 'l_1' made this script work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 May 2020 18:35:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getparameterastext-returning-only-one-character-in/m-p/134078#M10487</guid>
      <dc:creator>MichałKozłowski</dc:creator>
      <dc:date>2020-05-23T18:35:47Z</dc:date>
    </item>
  </channel>
</rss>

