<?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: Programatically format numeric fields with arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285754#M22077</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again Curtis, thanks!&lt;/P&gt;&lt;P&gt;The tool's workflow copied an MXD, updated data sources of layers and refreshed table values drawn from&amp;nbsp; data driven feature class attributes. I was initially losing the manually set numeric field formats, but that was due to my order of operations. I'll update the discussion post with the final findings!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 May 2019 17:51:38 GMT</pubDate>
    <dc:creator>Yuriko</dc:creator>
    <dc:date>2019-05-10T17:51:38Z</dc:date>
    <item>
      <title>Programmatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285747#M22070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;***&lt;/P&gt;&lt;P&gt;UPDATE May 10, 2019. Findings so far confirm there is no programmatic access to the Numeric Field Display Properties (e.g. Pad with zeroes, Show thousands separators, etc). There is an open &lt;A _jive_internal="true" href="https://community.esri.com/ideas/6759-expose-the-arcmap-layer-properties-through-arcpy"&gt;IDEAS&lt;/A&gt; topic for this functionality.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Until implemented, the workaround is to access the property in a saved layer file and applied to a feature layer. An example is provided by Curtis Price below.&lt;/P&gt;&lt;P&gt;***&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know how to manually format numeric fields as described under &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/formatting-numeric-fields-in-tables.htm"&gt;Formatting numeric fields in tables&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I would like to access and script the functionality to display numeric fields with thousand separators in a Python Toolbox tool. Is this possible? The number display format properties listed in the screen capture below aren't exposed via Field properties, Table views or any other objects I have researched. &lt;IMG __jive_id="445454" class="image-1 jive-image" height="386" src="https://community.esri.com/legacyfs/online/445454_pastedImage_1.png" width="398" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 May 2019 17:47:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285747#M22070</guid>
      <dc:creator>Yuriko</dc:creator>
      <dc:date>2019-05-01T17:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Programatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285748#M22071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sadly, most formatting options of which you seek return strings&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{:,}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;num&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;'123,456,789.01'&lt;/SPAN&gt;

f&lt;SPAN class="string token"&gt;"{num:,}"&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;'123,456,789.01'&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As of recent versions of python (3.6 I think), you can format numbers with the underscore to make it easier to read when you are creating or using them, they don't retain the syntax when exporting unless you format it back as a string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;newnum &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; 123_456_789&lt;SPAN class="number token"&gt;.01&lt;/SPAN&gt;

newnum
&lt;SPAN class="number token"&gt;123456789.01&lt;/SPAN&gt;‍‍‍‍

f&lt;SPAN class="string token"&gt;"{newnum:,}"&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;'123,456,789.01'&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:48:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285748#M22071</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T13:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Programatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285749#M22072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan, I think you're missing the question. Yuriko wants to modify the display properties of fields within a layer object in ArcMap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, the only way I know how to do this in&amp;nbsp;arcpy is to create a layer with the formatting properties set up ahead of time using the ArcMap user interface, save it as a .lyr file. Then at script run time, load the .lyr from disk and point its source property to a dataset. To get in this deep to the ArcMap object model you must&amp;nbsp;delve into .NET and do it in ArcObjects.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2019 02:37:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285749#M22072</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2019-05-02T02:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Programatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285750#M22073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahhh. for some reason, I thought he wanted to calculate a new field with the format desired format.&lt;/P&gt;&lt;P&gt;I just saw Python and thought about the python 3.6 underscore syntax which is great for working with big numbers and a compliment to the f-string formatting&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yup... can't be done &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt; &amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2019 03:37:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285750#M22073</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-05-02T03:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Programatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285751#M22074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Many thanks to both of you, Dan and Curtis! It is helpful to know both these things!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2019 21:41:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285751#M22074</guid>
      <dc:creator>Yuriko</dc:creator>
      <dc:date>2019-05-02T21:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Programatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285752#M22075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Curtis! As you clearly described, despite setting and saving the Feature Layer field property to display the thousand separators, when I update the Layer's data source the Layer's field properties return to the default without the separators. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2019 23:25:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285752#M22075</guid>
      <dc:creator>Yuriko</dc:creator>
      <dc:date>2019-05-02T23:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Programatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285753#M22076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the workflow I am suggesting.&amp;nbsp;southdakotacities.lyr is a layer file with the comma formatting saved from setting it up in ArcMap.&lt;/P&gt;&lt;P&gt;Of course this requires that the field with commas set (POPULATION in my case) is both in the .lyr file and in the target feature class (in this case wyoming_cities).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcpy &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; env
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcpy &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; mapping &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; AM

&lt;SPAN class="comment token"&gt;# get active data frame&lt;/SPAN&gt;
mxd &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; AM&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MapDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
df &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; mxd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;activeDataFrame

&lt;SPAN class="comment token"&gt;# get layer definition from layer file, (includes field formatting) &lt;/SPAN&gt;
lyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; AM&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Layer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"southdakota_cities.lyr"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# update name and source&lt;/SPAN&gt;
lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"wyoming_cities"&lt;/SPAN&gt;
lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replaceDataSource&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"FILEGDB_WORKSPACE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"wyoming_cities"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# add layer to map, this layer has wyoming_cities with commas in attribute table&lt;/SPAN&gt;
AM&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddLayer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;df&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:48:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285753#M22076</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T13:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Programatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285754#M22077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again Curtis, thanks!&lt;/P&gt;&lt;P&gt;The tool's workflow copied an MXD, updated data sources of layers and refreshed table values drawn from&amp;nbsp; data driven feature class attributes. I was initially losing the manually set numeric field formats, but that was due to my order of operations. I'll update the discussion post with the final findings!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 May 2019 17:51:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/285754#M22077</guid>
      <dc:creator>Yuriko</dc:creator>
      <dc:date>2019-05-10T17:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically format numeric fields with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/1545159#M72983</link>
      <description>&lt;P&gt;I created a new &lt;A href="https://community.esri.com/t5/python-ideas/allow-for-control-of-numeric-format-in-python/idi-p/1545154/jump-to/first-unread-message" target="_blank" rel="noopener"&gt;ESRI IDEA&lt;/A&gt; for this problem that is not really yet resolved when using in stand-alone python script.&lt;/P&gt;&lt;P&gt;Consider upvoting.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 13:08:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmatically-format-numeric-fields-with-arcpy/m-p/1545159#M72983</guid>
      <dc:creator>AntoinePrince1805</dc:creator>
      <dc:date>2024-10-03T13:08:50Z</dc:date>
    </item>
  </channel>
</rss>

