<?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: Field Calc VB to Python help, ( will trade work) in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501490#M1676</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Fortunately Python is very good with text manipulation. All you need to do is the "lstrip" string method (to cut off a specified character of the left side of the text string):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;address = "000718 Puget St. SW"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;newAddress = address.lstrip("0")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print newAddress&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'718 Puget St. SW'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In a Field calculator expression, it would look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(myFC, "NEW_ADDRESS", "!FUBAR_ADDRESS!.lstrip('0')", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or you feel invincible, you could overwrite the existing field:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(myFC, "ADDRESS", "!ADDRESS!.lstrip('0')", "PYTHON")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Dec 2010 17:52:45 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2010-12-07T17:52:45Z</dc:date>
    <item>
      <title>Field Calc VB to Python help, ( will trade work)</title>
      <link>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501489#M1675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can anyone point me in the right direction of getting this field calculation to run in a python script ? If needed, I would be willing to help you out on any geospatial issues you may have.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The goal of this script is removing leading zeros from my address field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To go from &lt;/SPAN&gt;&lt;STRONG&gt;0001205 Main St &lt;/STRONG&gt;&lt;SPAN&gt;to &lt;/SPAN&gt;&lt;STRONG&gt;1205 Main St&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;VB:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression: str1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dim str1 as string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; dim str2() as string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; str2 =split(&amp;nbsp; [SIT_FULL_S] ," ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; dim cnt as integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; dim lngvalue as long&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lngvalue = clng( str2(0) ) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; str1 = str1 &amp;amp; lngvalue &amp;amp; " "&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for cnt =1 to UBOUND(str2) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; str1 = str1 &amp;amp; str2(cnt) &amp;amp; " "&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;next&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what I have converted to Python so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(fc + "\\Parcels.shp", "SIT_FULL_S", "myfunction(!SIT_FULL_S!)", "PYTHON", "def myfunction(str1):\n dim str1 = string()\n str2 = string()\n str2 =split( !SIT_FULL_S! ,\' \')\n cnt = integer()\n lngvalue = long()\n lngvalue = clng( str2(0) ) \n str1 = str1 + lngvalue + \' \'\n for cnt =1 to UBOUND(str2) \n&amp;nbsp;&amp;nbsp;&amp;nbsp; str1 = str1 + str2(cnt) + \' \'\\n next")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the problems may be my definiton of the function AND this VB line &lt;/SPAN&gt;&lt;STRONG&gt;for cnt =1 to UBOUND(str2)&lt;/STRONG&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 16:16:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501489#M1675</guid>
      <dc:creator>TurnerNowak</dc:creator>
      <dc:date>2010-12-07T16:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc VB to Python help, ( will trade work)</title>
      <link>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501490#M1676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Fortunately Python is very good with text manipulation. All you need to do is the "lstrip" string method (to cut off a specified character of the left side of the text string):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;address = "000718 Puget St. SW"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;newAddress = address.lstrip("0")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print newAddress&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'718 Puget St. SW'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In a Field calculator expression, it would look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(myFC, "NEW_ADDRESS", "!FUBAR_ADDRESS!.lstrip('0')", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or you feel invincible, you could overwrite the existing field:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(myFC, "ADDRESS", "!ADDRESS!.lstrip('0')", "PYTHON")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 17:52:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501490#M1676</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-12-07T17:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc VB to Python help, ( will trade work)</title>
      <link>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501491#M1677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: mykonosman&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, that is much easier. Thanks for the help !&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 23:03:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501491#M1677</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2010-12-07T23:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc VB to Python help, ( will trade work)</title>
      <link>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501492#M1678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a similar question, though maybe easier, so I have a Unique ID field but its a text field with characters in the string (9X123456) and the create Lines from X,Y tool requires the ID field to be a number. I came up with 123456 &amp;amp; 01 (X is now a number) &amp;amp; 9 ie 9X123456 becomes 123456019. I can do this pretty easy in VB Script in the Field Calculator in a temp text field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So my question is how do I say this expression in Python;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[GEOID] &amp;amp; "019" &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!GEOID! &amp;amp; '019'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know its not b/c it doesn't seem to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, if possible is there any way to say the GEOID field is text, calculate and then say everything in this text expression is now numeric so I can avoid using this temp field?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;say; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;long(str(!GEOID!) &amp;amp; '019')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Danny&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Dec 2010 15:26:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501492#M1678</guid>
      <dc:creator>DanielSheehan</dc:creator>
      <dc:date>2010-12-09T15:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc VB to Python help, ( will trade work)</title>
      <link>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501493#M1679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: dms8md23&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This looks like it works&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;long(str(!GEOID!) + '019')&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Dec 2010 16:07:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501493#M1679</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2010-12-09T16:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc VB to Python help, ( will trade work)</title>
      <link>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501494#M1680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: csny490&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Python concatenate operator is actually '+', so for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "my" + " " + "dog"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'my dog'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So the expression would be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;long(str(!GEOID!) + '001' + '009')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another simple way of "integerizing" your string unique id:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Run a frequency on your string field using the Frequency tool. Then join the frequency table to the original table. The OBJECTID field (a long integer BTW) of the frequency table gives you a 1-to-1 with the text version unique id.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also do something similar using cursors via Python...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Dec 2010 16:39:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/field-calc-vb-to-python-help-will-trade-work/m-p/501494#M1680</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2010-12-09T16:39:28Z</dc:date>
    </item>
  </channel>
</rss>

