<?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: Problem with calculate field in python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634106#M49384</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for help. If I try this:&lt;/P&gt;&lt;P&gt;print (('R:\\Karto\Bierer2014\\Datenabgabe\\20150113_Brandt\\raster\\' + '(!OBJECT_ID!)' + ext).strip('utf-8'))&lt;/P&gt;&lt;P&gt;I get this message:&lt;/P&gt;&lt;P&gt;AttributeError: 'str' object has no attribute 'OBJECT_ID'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do understand that I haven't told python properly that it should take attribute of the field Objec_ID of the shape.&lt;/P&gt;&lt;P&gt;How to do that.&lt;/P&gt;&lt;P&gt;Also tried with no sucess:&lt;/P&gt;&lt;P&gt;for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unique_values = set(row.getValue(Field) for row in iter(arcpy.SearchCursor(Path).next, None))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Jan 2015 11:56:13 GMT</pubDate>
    <dc:creator>JohannesBierer</dc:creator>
    <dc:date>2015-01-27T11:56:13Z</dc:date>
    <item>
      <title>Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634102#M49380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Somehow I can't manage to get this to work:&lt;/P&gt;&lt;P&gt;The goal is to write a path into a field combined with the attribute Object_ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
Fgdb = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\RasterCatalog.gdb"
arcpy.env.workspace = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\RasterCatalog.gdb"
# Ausgabepfad = (r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster").strip()
Ausgabepfad = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster"
ext = ".jpg"
# arcpy.AddField_management(Ausgabepfad + "\Orthos_Nummern.shp", "IMAGE", "TEXT", 100) # , "", "", "refcode", "NULLABLE", "REQUIRED")
# print (Ausgabepfad + "\Orthos_Nummern.shp")
# print ("\"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\"" + ext)
# print (Ausgabepfad + "\\Orthos_Nummern.shp")
rows = arcpy.UpdateCursor(Ausgabepfad + "\Orthos_Nummern.shp")&amp;nbsp; 
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # yield ('"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\"' + '(!OBJECT_ID!)' + ext).strip()
&amp;nbsp;&amp;nbsp;&amp;nbsp; # print (('"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\ + '(!OBJECT_ID!)' + 'ext').strip('utf-8'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print (('R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\' + '(!OBJECT_ID!)' + 'ext').strip('utf-8'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; # arcpy.CalculateField_management(Ausgabepfad + "\\Orthos_Nummern.shp", "IMAGE", 
('"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\"' + '(!OBJECT_ID!)' + ext).strip('utf-8'), "PYTHON")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;???&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:58:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634102#M49380</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2021-12-12T02:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634103#M49381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;why is&amp;nbsp; '(!OBJECT_ID!)' in round brackets? and if it is numeric, it needs to be converted to a string ... str( ... )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 10:20:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634103#M49381</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-01-27T10:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634104#M49382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Johannes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why don't you try to write every backslash double? I mean that every special character need to be scaped, and the scape character is the backslash.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;print (('R:\\Karto\Bierer2014\\Datenabgabe\\20150113_Brandt\\raster\\' + '(!OBJECT_ID!)' + 'ext').strip('utf-8'))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;Luis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 10:34:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634104#M49382</guid>
      <dc:creator>Luis_ÁngelPascual_Camino</dc:creator>
      <dc:date>2015-01-27T10:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634105#M49383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;...I meaned "escaped"... sorry.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 10:54:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634105#M49383</guid>
      <dc:creator>Luis_ÁngelPascual_Camino</dc:creator>
      <dc:date>2015-01-27T10:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634106#M49384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for help. If I try this:&lt;/P&gt;&lt;P&gt;print (('R:\\Karto\Bierer2014\\Datenabgabe\\20150113_Brandt\\raster\\' + '(!OBJECT_ID!)' + ext).strip('utf-8'))&lt;/P&gt;&lt;P&gt;I get this message:&lt;/P&gt;&lt;P&gt;AttributeError: 'str' object has no attribute 'OBJECT_ID'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do understand that I haven't told python properly that it should take attribute of the field Objec_ID of the shape.&lt;/P&gt;&lt;P&gt;How to do that.&lt;/P&gt;&lt;P&gt;Also tried with no sucess:&lt;/P&gt;&lt;P&gt;for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unique_values = set(row.getValue(Field) for row in iter(arcpy.SearchCursor(Path).next, None))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 11:56:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634106#M49384</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2015-01-27T11:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634107#M49385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To create a unique list of values from a field inside a cursor would repeat that for every feature, while the list remains the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I understand correctly, you want to construct a path (string) and store that in a field. You could use this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
Ausgabepfad = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster"
fgdb = "RasterCatalog.gdb" # you're not using this
arcpy.env.workspace = os.path.join(Ausgabepfad, fgdb) # you're not using this
ext = ".jpg"
fc = os.path.join(Ausgabepfad, "Orthos_Nummern.shp")
fld_oid = "OBJECT_ID" # or: arcpy.Describe(fc).OIDFieldName
fld_out = "YourOutputFieldName" # should exist in shapefile

rows = arcpy.UpdateCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.join(Ausgabepfad, "{0}{1}".format(row.getValue(fld_oid), ext))
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(fld_out, path)
&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)

# or if you have a version &amp;gt;= 10.1 SP1, you could use the arc.da.UpdateCursor
flds = (fld_oid, fld_out)
with arcpy.da.UpdateCursor(fc, flds) as curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = os.path.join(Ausgabepfad, "{0}{1}".format(row[0], ext))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:58:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634107#M49385</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T02:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634108#M49386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look good Xander, unfortunaltely&lt;/P&gt;&lt;P&gt;path = os.path.join(Ausgabepfad, "{0}{1}".format(row.getValue(fld_oid), ext))&lt;/P&gt;&lt;P&gt;leads to that:&lt;/P&gt;&lt;P&gt;R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\35355481.0.jpg&lt;/P&gt;&lt;P&gt;I would need it without .0&amp;nbsp; = xxx481.jpg ?&lt;/P&gt;&lt;P&gt;and row.getValue = TypeError: 'float' object is not subscriptable ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 13:31:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634108#M49386</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2015-01-27T13:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634109#M49387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;On line 12, you shoud convert the float to int to avoid the ".0":&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;path = os.path.join(Ausgabepfad, "{0}{1}".format(int(row.getValue(fld_oid)), ext))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other error is a bit weird (maybe that´s why I don't use the old cursor anymore...) If you have 10.1 SP1 or higher switch to the arcpy.daUpdateCursor syntax. Which would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;flds = (fld_oid, fld_out)
with arcpy.da.UpdateCursor(fc, flds) as curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = os.path.join(Ausgabepfad, "{0}{1}".format(int(row[0]), ext))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:58:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634109#M49387</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T02:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634110#M49388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately I can't use arcpy.da. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Small mistake in your code:&lt;/P&gt;&lt;P&gt;Not:&lt;/P&gt;&lt;P&gt;curs.updateRow(row)&lt;/P&gt;&lt;P&gt;It's ?:&lt;/P&gt;&lt;P&gt;rows.updateRow(row)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Had only to make the value to integer:&lt;/P&gt;&lt;P&gt;fld_oid1 = int(row.getValue(fld_oid))&lt;/P&gt;&lt;P&gt;int_fld_oid1 = str(fld_oid1)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jan 2015 07:23:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634110#M49388</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2015-01-28T07:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with calculate field in python</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634111#M49389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;On line 2 of the code you mention, I created a cursor object and named it "curs". You can call it "rows" or anything you like. That doesn't matter, it is the name you use for a variable (in this case a cursor object). So it is not an error, but a way I like to call the object/variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jan 2015 11:42:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-calculate-field-in-python/m-p/634111#M49389</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-01-28T11:42:28Z</dc:date>
    </item>
  </channel>
</rss>

