<?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: Can f-strings be used in script tools? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1082839#M61866</link>
    <description>&lt;P&gt;f"{}"&amp;nbsp; == "{}".format()&lt;/P&gt;&lt;P&gt;However, the f-strings have almost implemented all the capabilities of the .format version.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the casual/infrequent user, it is sometimes a preference between pre-fix versus post-fix notation.&lt;/P&gt;&lt;P&gt;For others it is the onerous task of typing the extra "ormat".&lt;/P&gt;&lt;P&gt;In any event, all variables/strings passed to either case needs to be raw-encoded at source prior to formatting to avoid nasty unexpected errors.&lt;/P&gt;&lt;P&gt;Try this on.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;b ="{}".format(r"Ooops\a\b\t")
b
'Ooops\\a\\b\\t'
# ---- or
a = r"Ooops\a\b\t"
f"{a}"
'Ooops\\a\\b\\t'

# ----- now, omit raw encoding
c ="{}".format("Ooops\a\b\t")
c
'Ooops\x07\x08\t'
# --- etcetera&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 26 Jul 2021 21:44:39 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-07-26T21:44:39Z</dc:date>
    <item>
      <title>Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1082815#M61863</link>
      <description>&lt;P&gt;Can script tools use f-strings? I'm getting an 'ERROR 000354: The name contains invalid characters'.&amp;nbsp; The line that is causing the error is as follows -&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.FeatureClassToFeatureClass_conversion('Proposed_OLT_LCP_Boundaries', scratch, f'{lcpNameFixed}_Boundary', exp)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Here is how lcpNameFixed is assigned.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;lcps = arcpy.GetParameterAsText(&lt;SPAN&gt;0&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;PRE&gt;lcpNameFixed = lcp.replace(&lt;SPAN&gt;'-'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The value list of lcps has dashes ('-') but the lcpNameFixed takes the dashes out. The lcps value list doesn't start with numbers either.&amp;nbsp; I just want to rule out if the f-string might be causing this invalid name error.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 20:37:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1082815#M61863</guid>
      <dc:creator>ChrisGAEG</dc:creator>
      <dc:date>2021-07-26T20:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1082826#M61865</link>
      <description>&lt;P&gt;I'd say your answer is "Yes" provided you're using the script tools with environments at version 3.6+ of Python. If you're reasonably sure no one's using a version older than that then your tools should be fine. However, if you want to ensure compatibility with older versions then you're stuck with .format, I guess.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 21:20:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1082826#M61865</guid>
      <dc:creator>emedina</dc:creator>
      <dc:date>2021-07-26T21:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1082839#M61866</link>
      <description>&lt;P&gt;f"{}"&amp;nbsp; == "{}".format()&lt;/P&gt;&lt;P&gt;However, the f-strings have almost implemented all the capabilities of the .format version.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the casual/infrequent user, it is sometimes a preference between pre-fix versus post-fix notation.&lt;/P&gt;&lt;P&gt;For others it is the onerous task of typing the extra "ormat".&lt;/P&gt;&lt;P&gt;In any event, all variables/strings passed to either case needs to be raw-encoded at source prior to formatting to avoid nasty unexpected errors.&lt;/P&gt;&lt;P&gt;Try this on.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;b ="{}".format(r"Ooops\a\b\t")
b
'Ooops\\a\\b\\t'
# ---- or
a = r"Ooops\a\b\t"
f"{a}"
'Ooops\\a\\b\\t'

# ----- now, omit raw encoding
c ="{}".format("Ooops\a\b\t")
c
'Ooops\x07\x08\t'
# --- etcetera&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 26 Jul 2021 21:44:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1082839#M61866</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-07-26T21:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1084395#M61900</link>
      <description>&lt;P&gt;Correct, I found that one of my layers had a '/' in the name.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&amp;nbsp; F-strings can be used in line as arguments. Thanks for the response.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 13:40:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1084395#M61900</guid>
      <dc:creator>ChrisGAEG</dc:creator>
      <dc:date>2021-07-30T13:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1084396#M61901</link>
      <description>&lt;P&gt;Onerous indeed. Thanks again for the clarification Dan!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 13:41:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1084396#M61901</guid>
      <dc:creator>ChrisGAEG</dc:creator>
      <dc:date>2021-07-30T13:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090257#M62110</link>
      <description>&lt;P&gt;They can in main scripts but I've noticed validation scripts don't like them.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 06:28:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090257#M62110</guid>
      <dc:creator>MattHowe</dc:creator>
      <dc:date>2021-08-19T06:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090332#M62116</link>
      <description>&lt;P&gt;I'll add that I've noticed the consolidation and packaging tools tend to convert f-strings to .format and then assign them to&amp;nbsp;&lt;SPAN&gt;g_ESRI_variables.&amp;nbsp; No idea why.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Generally speaking, I have little problem with f-strings but every so often Pro [2.6] returns an error.&amp;nbsp; Sometimes it's solved by simply closing the program and re-opening.&amp;nbsp; It seems really inconsistent.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 13:22:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090332#M62116</guid>
      <dc:creator>RyanDavis1</dc:creator>
      <dc:date>2021-08-19T13:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090453#M62120</link>
      <description>&lt;P&gt;f strings are largely shortcuts to "".format .&amp;nbsp; there is no "real" advantage to using them and the capabilities of "format" haven't been completely replicated in f-strings.&amp;nbsp; Some people claim they are shorter but in reality most cases are only shorter by "ormat" characters &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 16:40:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090453#M62120</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-08-19T16:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090528#M62124</link>
      <description>&lt;P&gt;Totally agree. I find using them to create definition queries in scripts easier but more than anything I think they make code a bit easier to read for people new to Python.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 18:41:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1090528#M62124</guid>
      <dc:creator>MattHowe</dc:creator>
      <dc:date>2021-08-19T18:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can f-strings be used in script tools?</title>
      <link>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1234065#M66156</link>
      <description>&lt;P&gt;Do you mean Pyhton 3.6+?&lt;/P&gt;&lt;P&gt;I can say for experience that some of the arcpy tools in Python 3.7 (ArcGIS Pro 2.9) that some of the tools accept f-string as parameters other does not:&lt;/P&gt;&lt;P&gt;This example does not work (using the f-string in the where_clause parameter):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;where_clause_with_date_filter = f"{where_clause} AND {date_filter}"
points_select = arcpy.analysis.Select("{0}.{1}".format(schema_owner, TABLE_CAL_POINTS), r"memory\f{0}".format(uuid4().hex),where_clause_with_date_filter)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;generates the error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\Resources\ArcPy\arcpy\analysis.py", line 138, in Select
    raise e
  File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\Resources\ArcPy\arcpy\analysis.py", line 135, in Select
    retval = convertArcObjectToPythonObject(gp.Select_analysis(*gp_fixargs((in_features, out_feature_class, where_clause), True)))
  File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000358: Invalid expression f"{where_clause} AND {date_filter}"
Failed to execute (Select).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have tried to use the f-string in search cursor, and update cursor and found that in the feature_class parameter,m it does not accept f-strings, but in the where_clause it does:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor("{0}.{1}".format(schema_owner, TABLE_LINKAGES),
                                   ["REFERENCE_FEATURE_ID"],
                                   where_clause=f"PROJECT_ID = '{project_id}'") as cursor:&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 12:42:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-f-strings-be-used-in-script-tools/m-p/1234065#M66156</guid>
      <dc:creator>Cristian_Galindo</dc:creator>
      <dc:date>2022-11-22T12:42:06Z</dc:date>
    </item>
  </channel>
</rss>

