<?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: Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!! in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027124#M37449</link>
    <description>&lt;P&gt;This needs to be fixed...&lt;/P&gt;&lt;P&gt;f"Year = {a} And %VariableFieldName%&lt;/P&gt;&lt;P&gt;you are missing a " and, &lt;EM&gt;And&lt;/EM&gt; is &lt;EM&gt;and&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;try something along the lines of&lt;/P&gt;&lt;P&gt;'"Year" = {} and "{}" &amp;gt; 0'.format(a, v)&lt;/P&gt;&lt;P&gt;where 'a' is the year and v is the variable&lt;/P&gt;&lt;P&gt;Also packing your code into a one-liner isn't very useful&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - GeoNet, The Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;split this up&lt;/P&gt;&lt;LI-CODE lang="python"&gt;s_ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
with arcpy.EnvManager(scratchWorkspace=s_ws,workspace=ws):
    # etc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;to make it readable&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Feb 2021 12:25:25 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-02-16T12:25:25Z</dc:date>
    <item>
      <title>Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!!</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027101#M37443</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1108"&gt;@XanderBakker&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/167692"&gt;@DavidPike&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/433802"&gt;@SMehta&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I use an Inline Variable as a field name in Select Layer by Attribute in code block.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get the field name from multivalued variable table rather than from Attribute Table.&amp;nbsp; In &lt;EM&gt;Select Layer by Attribute&amp;nbsp;&amp;nbsp;&lt;/EM&gt;&amp;nbsp;&lt;STRONG&gt;Year and %VariableFieldName%&lt;/STRONG&gt;&amp;nbsp; value in &lt;STRONG&gt;"where clause"&lt;/STRONG&gt; comes from string Var2 as shown in the Image.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def x(Var2):
    for i in Var2.split(";"):
        a,b=shlex.split(i)
        with arcpy.EnvManager(scratchWorkspace=r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb", workspace=r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"):
lyr = arcpy.management.SelectLayerByAttribute(r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb\IDEAL_SHAPE_TimeSeries_Feb14_V1", "NEW_SELECTION", f"Year = {a} And %VariableFieldName% &amp;gt;0, None)

Data type : 
Long&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HussainMalik1_0-1613461576272.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/6114i708E8133B6346248/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HussainMalik1_0-1613461576272.png" alt="HussainMalik1_0-1613461576272.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I will really appreciate your help&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 08:04:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027101#M37443</guid>
      <dc:creator>HussainMalik1</dc:creator>
      <dc:date>2021-02-16T08:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!!</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027124#M37449</link>
      <description>&lt;P&gt;This needs to be fixed...&lt;/P&gt;&lt;P&gt;f"Year = {a} And %VariableFieldName%&lt;/P&gt;&lt;P&gt;you are missing a " and, &lt;EM&gt;And&lt;/EM&gt; is &lt;EM&gt;and&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;try something along the lines of&lt;/P&gt;&lt;P&gt;'"Year" = {} and "{}" &amp;gt; 0'.format(a, v)&lt;/P&gt;&lt;P&gt;where 'a' is the year and v is the variable&lt;/P&gt;&lt;P&gt;Also packing your code into a one-liner isn't very useful&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - GeoNet, The Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;split this up&lt;/P&gt;&lt;LI-CODE lang="python"&gt;s_ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
with arcpy.EnvManager(scratchWorkspace=s_ws,workspace=ws):
    # etc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;to make it readable&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 12:25:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027124#M37449</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-02-16T12:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!!</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027217#M37462</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp; for the help .&lt;/P&gt;&lt;P&gt;I am getting the following Syntax Error message&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ERROR 000539: File "&amp;lt;string&amp;gt;", line 6
SyntaxError: f-string: empty expression not allowed
Failed to execute (Calculate Value Multiple Fields).&lt;/LI-CODE&gt;&lt;P&gt;Please do check attached image for detail geoprocessing message&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hussain&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 17:18:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027217#M37462</guid>
      <dc:creator>HussainMalik1</dc:creator>
      <dc:date>2021-02-16T17:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!!</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027223#M37464</link>
      <description>&lt;P&gt;A screengrab of the code isn't going to help.&lt;/P&gt;&lt;P&gt;It also appears that you didn't take my suggestion of making the existing code more readable .&lt;/P&gt;&lt;P&gt;I can't tell if you fixed the error I pointed out in your expression&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 17:22:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027223#M37464</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-02-16T17:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!!</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027236#M37466</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed it according to your advice and it does looks better though.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Expression: x(("%VT%")
import shlex
s_ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
tbl= "IDEAL_SHAPE_TimeSeries_Feb14_V1"
def x(VT):
    for i in VT.split(";"):
        a,b,c=shlex.split(i)
        with arcpy.EnvManager(scratchWorkspace=s_ws, workspace=ws):
            lyr = arcpy.management.SelectLayerByAttribute(tbl, "NEW_SELECTION", f'"Year" = {} and "{}"&amp;gt;0'.format(a,b) , None)
            x = arcpy.management.GetCount(lyr)&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt; ERROR 000539:   File "&amp;lt;string&amp;gt;", line 9
SyntaxError: f-string: empty expression not allowed
 Failed to execute (Calculate Value Multiple Fields).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I am also trying to figure out the next part of this code where I have to calculate a new field and use the values from same field that I select in the code above (string "b" in this example ). Correct me if I am wrong if SeachCursor would be a good approach for that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 17:58:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027236#M37466</guid>
      <dc:creator>HussainMalik1</dc:creator>
      <dc:date>2021-02-16T17:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!!</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027247#M37468</link>
      <description>&lt;P&gt;throw in a print statement, it apparently doesn't see a or b&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 18:33:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027247#M37468</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-02-16T18:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Use inline variable for a field name in Select  Layer by Attribute ----HELP!!!!</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027477#M37509</link>
      <description>&lt;P&gt;So I have changed the &lt;STRONG&gt;SelectLayerByAttribute&lt;/STRONG&gt; and put the values (a and b) from string VT1&amp;nbsp; in curly brackets. where {a} = Year field and {b} = !ELECUSE_Large_Schools! field in attribute table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code below is a snippet from model builder Python in Arcpro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now this runs with no error message but it only selects the last part of the&amp;nbsp; VT1 string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i make it run for the whole VT1 variable?&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import shlex
s_ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
ws = r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"
tbl= "IDEAL_SHAPE_TimeSeries_Feb14_V1"
def x(VT1):
    for i in VT1.split(";"):
        a,b,c= shlex.split(i)
        with arcpy.EnvManager(scratchWorkspace=s_ws, workspace=ws):
            lyr= arcpy.management.SelectLayerByAttribute(tbl, "NEW_SELECTION", f'"Year" = {a} and "{b}"&amp;gt;0'.format(a,b),None)
            x= arcpy.management.GetCount(lyr)

def Model5(VT1=[[2020, "ELECUSE_Large_Schools", 0.2], [2040, "ELECUSE_Large_Schools", 0]]):  # Model 4

    # To allow overwriting outputs change overwriteOutput option to True.
    arcpy.env.overwriteOutput = False


    # Process: Calculate Value (Calculate Value) ()
    if VT1:
        Value = x("VT1")

if __name__ == '__main__':
    # Global Environment settings
    with arcpy.EnvManager(scratchWorkspace=r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb", workspace=r"D:\GBT_R_Drive\GBT_GIS\ICEMIgdb\ICEM\BldgEmission.gdb"):
        Model5(*argv[1:])
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 04:52:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-inline-variable-for-a-field-name-in-select/m-p/1027477#M37509</guid>
      <dc:creator>HussainMalik1</dc:creator>
      <dc:date>2021-02-17T04:52:38Z</dc:date>
    </item>
  </channel>
</rss>

