<?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: Variable/GetParameterAsText() within expression in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603493#M47154</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works perfectly now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Much appreciated Joshua.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Dec 2014 17:16:44 GMT</pubDate>
    <dc:creator>anTonialcaraz</dc:creator>
    <dc:date>2014-12-17T17:16:44Z</dc:date>
    <item>
      <title>Variable/GetParameterAsText() within expression</title>
      <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603491#M47152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to substitute the value "90" in &lt;STRONG&gt;Expression &lt;/STRONG&gt;with user input, that is: &lt;STRONG&gt;LSARqssedret&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried: &lt;STRONG&gt;Expression = "!Qs_Mt_a!" * float(&lt;STRONG&gt;LSARqssedret&lt;/STRONG&gt;)&lt;/STRONG&gt; but I'm not getting the right syntax within the expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import string
import math
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

arcpy.env.extent = arcpy.Extent(-180.0, -90.0, 180.0, 90.0)

INWorkspace = arcpy.GetParameterAsText(0)

StageAge = "Maas"

LSARqssedret = arcpy.GetParameterAsText(1)

GridPoints_ft2_qs = (INWorkspace + "\\" + StageAge + "_nodes_variable_ft_2")

arcpy.AddField_management(GridPoints_ft2_qs,"MASS_g_a","DOUBLE")

Expression = "!Qs_Mt_a! * 90"

arcpy.CalculateField_management(GridPoints_ft2_qs,"Mass_g_a",Expression,"PYTHON")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:52:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603491#M47152</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2021-12-12T01:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Variable/GetParameterAsText() within expression</title>
      <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603492#M47153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your current attempt isn't working because you are trying to multiply a string by a floating point number, which Python doesn't like so the CalculateField_management tool won't work either.&amp;nbsp; Try rewriting Line 21 as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14188357666207616 jive_text_macro" jivemacro_uid="_14188357666207616"&gt;&lt;P&gt;Expression = "!Qs_Mt_a! * {}".format(float(LSARqssedret))&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Dec 2014 17:02:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603492#M47153</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2014-12-17T17:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Variable/GetParameterAsText() within expression</title>
      <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603493#M47154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works perfectly now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Much appreciated Joshua.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Dec 2014 17:16:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603493#M47154</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2014-12-17T17:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Variable/GetParameterAsText() within expression</title>
      <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603494#M47155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm dealing with a bit more complex expression now but I don't quite get it right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got the first part (in bold) but I cannot quite figure out the second part of the expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would much appreciate some help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import string
import math
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

arcpy.env.extent = arcpy.Extent(-180.0, -90.0, 180.0, 90.0)

INWorkspace = arcpy.GetParameterAsText(0)

StageAge = "Maas"

TOCDrySedDen = arcpy.GetParameterAsText(1)

Porosity = arcpy.GetParameterAsText(2)

GridPoints_ft2_qs = (INWorkspace + "\\" + StageAge + "_nodes_variable_ft_2")

arcpy.AddField_management(GridPoints_ft2_qs,"cm_yr","DOUBLE")


Expression = ("!g_cm2_yr! / {}".format(float(TOCDrySedDen)))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

arcpy.CalculateField_management(GridPoints_ft2_qs,"cm_yr", Expression, "PYTHON_9.3")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# EXPRESSION CALCULATION: &lt;STRONG&gt;(!g_cm2_yr! / float(arcpy.GetParameterAsText(1)))&lt;/STRONG&gt; *&lt;/P&gt;&lt;P&gt;((float(arcpy.GetParameterAsText(2))/100) / (1-float(arcpy.GetParameterAsText(2))/100))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:52:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603494#M47155</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2021-12-12T01:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Variable/GetParameterAsText() within expression</title>
      <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603495#M47156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to build the substitution string correctly to use with the format string function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2/library/functions.html#format"&gt;https://docs.python.org/2/library/functions.html#format&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14189009802408951" jivemacro_uid="_14189009802408951" modifiedtitle="true"&gt;&lt;P&gt;Expression = "(!g_cm2_yr! / {0})*({1}/{2})".format(arcpy.GetParameterAsText(1),float(arcpy.GetParameterAsText(2))/100, 1-float(arcpy.GetParameterAsText(2)/100))&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Dec 2014 11:10:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603495#M47156</guid>
      <dc:creator>OwainCatton</dc:creator>
      <dc:date>2014-12-18T11:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Variable/GetParameterAsText() within expression</title>
      <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603496#M47157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you ever so much Owain. I understand now the logic behind it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Dec 2014 11:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/603496#M47157</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2014-12-18T11:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Variable/GetParameterAsText() within expression</title>
      <link>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/1199087#M65181</link>
      <description>&lt;P&gt;I was able to use your answer to the original question for parts of my calculation but now I'm running into an issue when trying to add up those parts. The goal is to multiply a field (scores) by a number inputted by the user (the weight) for six different fields, then sum those all together, and divide by another field. When I use the "+" symbol I believe it thinks I want to concatenate everything. I've tried using the sum function but get an error saying it can't sum strings. Here's my code.&lt;/P&gt;&lt;P&gt;# This script calculates the Composite Burden Score for each gas station in R3 using user-defined weights for the inputs.&lt;BR /&gt;# The Composite Burden Score is calculated by summing the weighted scores for SVI, Floodplain, Highway, Evacuation, Demand, and Supply and then dividing by the Community Resilience score.&lt;/P&gt;&lt;P&gt;from ntpath import join&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;# Set Environments&lt;BR /&gt;env.workspace = arcpy.GetParameterAsText(0)&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;BR /&gt;env.extent = arcpy.GetParameterAsText(1)&lt;/P&gt;&lt;P&gt;# Set Parameters&lt;BR /&gt;# By default, each input is equally weighted at 1/6th (or 0.16666)&lt;BR /&gt;Gas_Stations = arcpy.GetParameterAsText(2)&lt;BR /&gt;SVI_weight = arcpy.GetParameterAsText(3) or 0.16666&lt;BR /&gt;Floodplain_weight = arcpy.GetParameterAsText(4) or 0.16666&lt;BR /&gt;Highway_weight = arcpy.GetParameterAsText(5) or 0.16666&lt;BR /&gt;Evacuation_weight = arcpy.GetParameterAsText(6) or 0.16666&lt;BR /&gt;Demand_weight = arcpy.GetParameterAsText(7) or 0.16666&lt;BR /&gt;Supply_weight = arcpy.GetParameterAsText(8) or 0.16666&lt;/P&gt;&lt;P&gt;Expression = (("!SVI_Score! * {}".format(float(SVI_weight))) + ("!Floodplain_Score! * {}".format(float(Floodplain_weight))) + ("!Highway_Score! * {}".format(float(Highway_weight))) + ("!Evacuation_Score! * {}".format(float(Evacuation_weight))) + ("!Demand_Score! * {}".format(float(Demand_weight))) + ("!Supply_Score! * {}".format(float(Supply_weight)))) / "!Resilience Score!"&lt;/P&gt;&lt;P&gt;# Calculated the Composite Burden Score&lt;BR /&gt;arcpy.CalculateField_management(Gas_Stations, "Composite_Burden_Score_Weight", Expression, "PYTHON")&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 18:57:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-getparameterastext-within-expression/m-p/1199087#M65181</guid>
      <dc:creator>AmoryH</dc:creator>
      <dc:date>2022-08-03T18:57:49Z</dc:date>
    </item>
  </channel>
</rss>

