<?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: Modify feature class file name using f string in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643814#M74635</link>
    <description>&lt;P&gt;It is! In Python, strings implement the Sequence protocol, so you can iterate them and slice them like lists. The [3:] syntax is a slice that starts after the 3rd element and runs to the end. you can also truncate the last 3 with [3:-3] or get every other character between the first and last 3 with [3:-3:2]&lt;/P&gt;&lt;LI-CODE lang="c"&gt;&amp;gt;&amp;gt;&amp;gt; text = "abc_hello-world"
&amp;gt;&amp;gt;&amp;gt; text[3:]
... '_hello-world'
&amp;gt;&amp;gt;&amp;gt; text[3:-3]
... '_hello-wo'
&amp;gt;&amp;gt;&amp;gt; text[3:-3:2]
... '_el-o'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Aug 2025 16:33:56 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2025-08-20T16:33:56Z</dc:date>
    <item>
      <title>Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643421#M74625</link>
      <description>&lt;P&gt;Hello, I am pretty new with using python in Pro.&amp;nbsp; I need to modify feature class output names as they are being generated, or after they are created.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of features in a feature dataset (since this is a list, I am assuming using listFeatureClass, for loop, and&amp;nbsp;f strings is how I cycle through the layers)&lt;/P&gt;&lt;P&gt;EX_feature1&lt;/P&gt;&lt;P&gt;EX_feature2&lt;/P&gt;&lt;P&gt;EX_feature3&lt;/P&gt;&lt;P&gt;I want to remove the "EX_" from the feature class name and add "TR" in its place.&lt;/P&gt;&lt;P&gt;Is this a strip function?&amp;nbsp; can that be applied to fc names? Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 19:11:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643421#M74625</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-19T19:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643426#M74626</link>
      <description>&lt;P&gt;replace should work&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fcs = ["c:/path/EX_feature1","c:/path/EX_feature2", "c:/path/EX_feature3"]

out_fcs = [i.replace("EX_", "TR") for i in fcs]

out_fcs
['c:/path/TRfeature1', 'c:/path/TRfeature2', 'c:/path/TRfeature3']&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 19 Aug 2025 19:21:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643426#M74626</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-08-19T19:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643569#M74627</link>
      <description>&lt;P&gt;If you know you just need to replace the first 3 characters (say it was a state code with an underscore or something) you could also do:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;out_fcs = [f"TR{fc[3:]}" for fc in fcs]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using replace can sometimes burn you since by default it replaces *all* matching substrings unless you specify a limit. Meaning "aaabbbaaa".replace("a", "b") will give you "bbbbbbbbb" or "tr_tracks".replace("tr", "ex") would give you "ex_exacks"&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 04:41:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643569#M74627</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-08-20T04:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643696#M74631</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 12:46:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643696#M74631</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-20T12:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643697#M74632</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/909600"&gt;@SeanLukacs&lt;/a&gt;,&lt;BR /&gt;If you need a bit more robustness on future data sets you could look at regex substitution (re.sub()).&amp;nbsp; re.sub() will gracefully handle start matches, multiple matches, and non-matches with about the same amount of code.&amp;nbsp; Here's an example:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import re

fcs = [
    "EX_feature1",
    "EX_feature2",
    "feature4",
    "EX_feature5_EX_",
]
print(f"Original: {fcs}")
print(f'string replace: {[i.replace("EX_", "TR_") for i in fcs]}')
print(f'string slicer: {[f"TR_{fc[3:]}" for fc in fcs]}')
print(f"regex substitution: {[re.sub(r'^EX_', 'TR_', fc) for fc in fcs]}")&lt;/LI-CODE&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Original: ['EX_feature1', 'EX_feature2', 'feature4', 'EX_feature5_EX_']
string replace: ['TR_feature1', 'TR_feature2', 'feature4', 'TR_feature5_TR_']
string slicer: ['TR_feature1', 'TR_feature2', 'TR_ture4', 'TR_feature5_EX_']
regex substitution: ['TR_feature1', 'TR_feature2', 'feature4', 'TR_feature5_EX_']&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&amp;lt;Note: I changed from required 'TR' to 'TR_' for readability in this example only.&amp;gt;&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;&lt;BR /&gt;Tyler&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 13:03:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643697#M74632</guid>
      <dc:creator>TylerT</dc:creator>
      <dc:date>2025-08-20T13:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643699#M74633</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; Is your example setting the output variable?&amp;nbsp; So I am clipping several layers and then renaming them to exclude the first 3 characters and replace with a different amount of characters, would that still work?&lt;BR /&gt;&lt;BR /&gt;ex. "EX_" gets removed and I add in "TR100yr_".&amp;nbsp; so then my version of your line looks like&amp;nbsp;outFeature = [f"TR100yr_{fc[3:]}" for fc in fcs].&amp;nbsp; Is the "3" just the number of characters to replace or an index?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 12:50:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643699#M74633</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-20T12:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643709#M74634</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/530005"&gt;@TylerT&lt;/a&gt;&amp;nbsp;Thanks for that!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 13:08:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643709#M74634</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-20T13:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643814#M74635</link>
      <description>&lt;P&gt;It is! In Python, strings implement the Sequence protocol, so you can iterate them and slice them like lists. The [3:] syntax is a slice that starts after the 3rd element and runs to the end. you can also truncate the last 3 with [3:-3] or get every other character between the first and last 3 with [3:-3:2]&lt;/P&gt;&lt;LI-CODE lang="c"&gt;&amp;gt;&amp;gt;&amp;gt; text = "abc_hello-world"
&amp;gt;&amp;gt;&amp;gt; text[3:]
... '_hello-world'
&amp;gt;&amp;gt;&amp;gt; text[3:-3]
... '_hello-wo'
&amp;gt;&amp;gt;&amp;gt; text[3:-3:2]
... '_el-o'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 16:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643814#M74635</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-08-20T16:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643883#M74638</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;&amp;nbsp;That seemed to do the trick for my use case, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 19:18:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1643883#M74638</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-20T19:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Modify feature class file name using f string</title>
      <link>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1645722#M74661</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/909600"&gt;@SeanLukacs&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;I noticed in the Python docs that `string.replace()` has an optional &lt;EM&gt;count&lt;/EM&gt;&amp;nbsp;keyword giving it a bit more flexibility.&amp;nbsp;&amp;nbsp;If keyword &lt;EM&gt;count&lt;/EM&gt; is passed, only the first &lt;EM&gt;count&lt;/EM&gt; occurrences are replaced.&amp;nbsp; This might be useful for your case also.&lt;BR /&gt;&lt;BR /&gt;Tyler&lt;/P&gt;</description>
      <pubDate>Tue, 26 Aug 2025 17:20:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modify-feature-class-file-name-using-f-string/m-p/1645722#M74661</guid>
      <dc:creator>TylerT</dc:creator>
      <dc:date>2025-08-26T17:20:05Z</dc:date>
    </item>
  </channel>
</rss>

