<?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: Using PyWin to take the first 11 characters from a field and apend &amp;quot;.pdf&amp;quot; to the end in a new field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253274#M19499</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmmm...two questions.&amp;nbsp; Have you tried replacing the single quote around your field names to double quotes?&amp;nbsp; And does it work, if not the way you eventually want, if you remove the substring portion?&amp;nbsp; As in row.setValue(field2, field + '.pdf')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Oct 2014 19:01:04 GMT</pubDate>
    <dc:creator>BrandonKeinath1</dc:creator>
    <dc:date>2014-10-23T19:01:04Z</dc:date>
    <item>
      <title>Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253271#M19496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two fields: "Report_Number" and "Hyperlink." I want to take the first 11 characters from Report_Number and add them to Hyperlink while apending ".pdf" to the end. The result would be similar to: Report_Number = 20120328021; Hyperlink = 20120328021.pdf&lt;/P&gt;&lt;P&gt;So far, I have:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14140888302474798" jivemacro_uid="_14140888302474798" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;field = 'Report_Number'&lt;/P&gt;
&lt;P&gt;field2 = 'Hyperlink'&lt;/P&gt;
&lt;P&gt;cursor = arcpy.UpdateCursor("CrashReport")&lt;/P&gt;
&lt;P&gt;for row in cursor:&lt;/P&gt;
&lt;P&gt;row.setValue(field2, field[:11]) + '.pdf')&lt;/P&gt;
&lt;P&gt;cursor.updateRow(row)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting an error: &lt;/P&gt;&lt;P&gt;Runtime error &lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 1044, in getValue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.GetValue(*gp_fixargs(args)))&lt;/P&gt;&lt;P&gt;RuntimeError: ERROR 999999: Error executing function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PLEASE HELP!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 18:32:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253271#M19496</guid>
      <dc:creator>BryceGardner1</dc:creator>
      <dc:date>2014-10-23T18:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253272#M19497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Bryce,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like you have an extra ) on line 6.&amp;nbsp; I don't think that's the issue but I'm not sure why it's there.&amp;nbsp; Can you print the values of field and field 2 as it loops through the cursor and make sure the values make sense?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Brandon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 18:45:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253272#M19497</guid>
      <dc:creator>BrandonKeinath1</dc:creator>
      <dc:date>2014-10-23T18:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253273#M19498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have also tried to simply print field by using the getValue command and I get the same error. It seems to have difficulty understanding the substring part. I can print just field, but when I try to just get the first 11 characters, it fails.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 18:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253273#M19498</guid>
      <dc:creator>BryceGardner1</dc:creator>
      <dc:date>2014-10-23T18:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253274#M19499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmmm...two questions.&amp;nbsp; Have you tried replacing the single quote around your field names to double quotes?&amp;nbsp; And does it work, if not the way you eventually want, if you remove the substring portion?&amp;nbsp; As in row.setValue(field2, field + '.pdf')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 19:01:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253274#M19499</guid>
      <dc:creator>BrandonKeinath1</dc:creator>
      <dc:date>2014-10-23T19:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253275#M19500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now it writes, "Report_Numb.pdf" to the Hyperlink field instead of the value from Report_Number field&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 19:20:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253275#M19500</guid>
      <dc:creator>BryceGardner1</dc:creator>
      <dc:date>2014-10-23T19:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253276#M19501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;x = row.getValue(field)&lt;/P&gt;&lt;P&gt;row.setValue(field2,x[:&lt;SPAN class="number"&gt;12]) + &lt;SPAN class="string"&gt;'.pdf'&lt;/SPAN&gt;) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;splitting it into pieces and assuming x is a string I think...untested&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 19:49:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253276#M19501</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-23T19:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253277#M19502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;Bryce&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;i cannot see where you are assigning your values from your row to the fields you are using, try something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;import&lt;/SPAN&gt; &lt;SPAN class="nn"&gt;arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="n"&gt;&lt;/SPAN&gt;fc = &lt;EM&gt;'insert path to feature class'&lt;/EM&gt;&lt;BR /&gt;&lt;SPAN class="n"&gt;fields&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;'Report_Number'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s" style="color: #a31515;"&gt;'Hyperlink'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="c" style="color: #008000;"&gt;# Create update cursor for feature class &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="c" style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="k" style="color: #0000ff;"&gt;with&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;da&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;UpdateCursor&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;fc&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;fields&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="k" style="color: #0000ff;"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cursor&lt;/SPAN&gt;&lt;SPAN class="p"&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;# For each row, evaluate the Report Number value (index position &lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;# of 0), and update Hyperlink (index position of 1)&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="k" style="color: #0000ff;"&gt;for&lt;/SPAN&gt; &lt;SPAN class="n"&gt;row&lt;/SPAN&gt; &lt;SPAN class="ow" style="color: #0000ff;"&gt;in&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cursor&lt;/SPAN&gt;&lt;SPAN class="p"&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="n"&gt;row&lt;/SPAN&gt;&lt;SPAN class="p"&gt;[&lt;/SPAN&gt;&lt;SPAN class="mi" style="color: #666666;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;]&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; row[0][:11] + ".pdf"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="k" style="color: #0000ff;"&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;# Update the cursor with the updated list&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="n"&gt;cursor&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;updateRow&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;row&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 19:59:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253277#M19502</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-10-23T19:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253278#M19503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THANKS!!!&lt;/P&gt;&lt;P&gt;That works!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 20:00:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253278#M19503</guid>
      <dc:creator>BryceGardner1</dc:creator>
      <dc:date>2014-10-23T20:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253279#M19504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Bryce,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;something that I found really helps in troubleshooting python when it runs embedded in other application, such as in the case of the ArcGIS environment, is winpdb (&lt;A href="http://winpdb.org"&gt;http://winpdb.org&lt;/A&gt;‌).&lt;/P&gt;&lt;P&gt;It might be a little overkill in your situation, but it will allow you to follow step by step what is happening within arcpy as it gets executed. &lt;/P&gt;&lt;P&gt;I've used it to debug add-ins as they run and it helped me immensely.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 20:22:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253279#M19504</guid>
      <dc:creator>AndreaVaccari</dc:creator>
      <dc:date>2014-10-23T20:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using PyWin to take the first 11 characters from a field and apend ".pdf" to the end in a new field</title>
      <link>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253280#M19505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;&lt;EM&gt;I have two fields: "Report_Number" and "Hyperlink." I want to take the first 11 characters from Report_Number and add them to Hyperlink while apending ".pdf" to the end. The result would be similar to: Report_Number = 20120328021; Hyperlink = 20120328021.pdf&lt;/EM&gt;&lt;/P&gt;

&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Another solution would be to use the Calculate Field tool:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14141203796411399 jive_text_macro" jivemacro_uid="_14141203796411399" modifiedtitle="true"&gt;
&lt;P&gt;expr = "'{}.pdf'.format(!REPORT_NUMBER![:11])"&lt;/P&gt;
&lt;P&gt;arcpy.CalculateField_management(tbl, "HYPERLINK", expr, "PYTHON")&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2014 03:13:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-pywin-to-take-the-first-11-characters-from-a/m-p/253280#M19505</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-24T03:13:49Z</dc:date>
    </item>
  </channel>
</rss>

