<?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: Calculating field, pad zeros to a max field width of 6 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546891#M42673</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for the suggestions Darren. The script now runs, but is not adding the 0's to the left side of the Segment_Code values. Any gotchas that I'm missing here?&lt;BR /&gt;&lt;BR /&gt;Michael&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just discovered the Segment_Code field was converted to numeric during the TableToTable conversion. Looks like I'll have to figure out a method to preserve the string field type before I can pad the 0's.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks all for the help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 May 2012 13:25:27 GMT</pubDate>
    <dc:creator>MichaelMiller2</dc:creator>
    <dc:date>2012-05-03T13:25:27Z</dc:date>
    <item>
      <title>Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546883#M42665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to calculate a field value so that I pad 0's to the existing values to a max width of 6 chars.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Being a python newbie, I'm a little shaky with coding. I've started with the following code and getting nowhere. Any help/direction is appreciated&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.CalculateField_management(outCrash, "Segment_Code", !Segment_Code!.ljust(!Segment_Code!,6,0), "PYTHON")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael Miller&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 18:45:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546883#M42665</guid>
      <dc:creator>MichaelMiller2</dc:creator>
      <dc:date>2012-05-02T18:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546884#M42666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Calculator Expression:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;str(!Segment_Code!).zfill(6) &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 19:34:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546884#M42666</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-05-02T19:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546885#M42667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Calculator Expression:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;str(!Segment_Code!).zfill(6) &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Darren.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's now returning a syntax error.......invalid syntax on the exp=.... line.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exp = str(!Segment_Code!).zfill(6)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(outCrash, exp, "PYTHON")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546885#M42667</guid>
      <dc:creator>MichaelMiller2</dc:creator>
      <dc:date>2021-12-11T23:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546886#M42668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you just need quotes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;exp = "str(!Segment_Code!).zfill(6)"
arcpy.CalculateField_management(outCrash, exp, "PYTHON")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546886#M42668</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T23:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546887#M42669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think you just need quotes:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;exp = "str(!Segment_Code!).zfill(6)"
arcpy.CalculateField_management(outCrash, exp, "PYTHON")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry to be a pest with this simple task, but still not working. Appears that is is treating the expression as the field.......confused.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It now returns the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000728: Field str(!Segment_Code!).zfill(6) does not exist within table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (CalculateField).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546887#M42669</guid>
      <dc:creator>MichaelMiller2</dc:creator>
      <dc:date>2021-12-11T23:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546888#M42670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Sorry to be a pest with this simple task, but still not working. Appears that is is treating the expression as the field.......confused.&lt;BR /&gt;&lt;BR /&gt;It now returns the following error:&lt;BR /&gt;&lt;BR /&gt;ERROR 000728: Field str(!Segment_Code!).zfill(6) does not exist within table&lt;BR /&gt;Failed to execute (CalculateField).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You are using the wrong syntax. Check your tool documentation here. &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000" rel="nofollow" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The expression is the third variable passed to the tool, the field is the second.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 20:52:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546888#M42670</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-05-02T20:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546889#M42671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You are using the wrong syntax. Check your tool documentation here. &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The expression is the third variable passed to the tool, the field is the second.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duh.....Thanks for pointing that out Mathew.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 May 2012 12:35:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546889#M42671</guid>
      <dc:creator>MichaelMiller2</dc:creator>
      <dc:date>2012-05-03T12:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546890#M42672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think you just need quotes:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;exp = "str(!Segment_Code!).zfill(6)"
arcpy.CalculateField_management(outCrash, exp, "PYTHON")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the suggestions Darren. The script now runs, but is not adding the 0's to the left side of the Segment_Code values. Any gotchas that I'm missing here?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:40:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546890#M42672</guid>
      <dc:creator>MichaelMiller2</dc:creator>
      <dc:date>2021-12-11T23:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating field, pad zeros to a max field width of 6</title>
      <link>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546891#M42673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for the suggestions Darren. The script now runs, but is not adding the 0's to the left side of the Segment_Code values. Any gotchas that I'm missing here?&lt;BR /&gt;&lt;BR /&gt;Michael&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just discovered the Segment_Code field was converted to numeric during the TableToTable conversion. Looks like I'll have to figure out a method to preserve the string field type before I can pad the 0's.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks all for the help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 May 2012 13:25:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-field-pad-zeros-to-a-max-field-width/m-p/546891#M42673</guid>
      <dc:creator>MichaelMiller2</dc:creator>
      <dc:date>2012-05-03T13:25:27Z</dc:date>
    </item>
  </channel>
</rss>

