<?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 FieldMap API : Strange Behavior. Can someone explain? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1260917#M67855</link>
    <description>&lt;P&gt;I am using arcpro3.0.3 and am using the TableToTable API to convert a shapefile .dbf file into .csv.&lt;/P&gt;&lt;P&gt;One of the arguments to TableToTable is a FieldMappings parameters, and I amusing this to rename all of the fields in the original shapefile.&lt;/P&gt;&lt;P&gt;The documentation of FieldMap has example code which looks like this (names of variables not the same as in documentation, but you get the idea)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;fm = arcpy.FieldMap()&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;fm.addInputField(tablename,oldfieldname)&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;outf = fm.outputField&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;outf.name = newfieldname&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;fm.outputField = out&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;The above code seems to work, but this code below&amp;nbsp; (which appears to me to have the same effect does not)&lt;BR /&gt;The&amp;nbsp; code which differs in the two examples is in &lt;FONT color="#FF0000"&gt;red&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;fm = arcpy.FieldMap()&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;fm.addInputField(tablename,oldfieldname)&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;fm.outputField.name = newfieldname&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;In the first case the field in question has its&amp;nbsp; name in the output &lt;EM&gt;.csv&lt;/EM&gt; file&amp;nbsp; changed (from &lt;STRONG&gt;oldfieldname&lt;/STRONG&gt; to &lt;STRONG&gt;newfieldname&lt;/STRONG&gt;; in the second case the field name remains unchanged. Why is that? To my eye both code snippets do exactly the same thing.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Feb 2023 15:13:40 GMT</pubDate>
    <dc:creator>RobertStevens</dc:creator>
    <dc:date>2023-02-23T15:13:40Z</dc:date>
    <item>
      <title>FieldMap API : Strange Behavior. Can someone explain?</title>
      <link>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1260917#M67855</link>
      <description>&lt;P&gt;I am using arcpro3.0.3 and am using the TableToTable API to convert a shapefile .dbf file into .csv.&lt;/P&gt;&lt;P&gt;One of the arguments to TableToTable is a FieldMappings parameters, and I amusing this to rename all of the fields in the original shapefile.&lt;/P&gt;&lt;P&gt;The documentation of FieldMap has example code which looks like this (names of variables not the same as in documentation, but you get the idea)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;fm = arcpy.FieldMap()&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;fm.addInputField(tablename,oldfieldname)&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;outf = fm.outputField&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;outf.name = newfieldname&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;fm.outputField = out&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;The above code seems to work, but this code below&amp;nbsp; (which appears to me to have the same effect does not)&lt;BR /&gt;The&amp;nbsp; code which differs in the two examples is in &lt;FONT color="#FF0000"&gt;red&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;fm = arcpy.FieldMap()&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;fm.addInputField(tablename,oldfieldname)&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;fm.outputField.name = newfieldname&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;In the first case the field in question has its&amp;nbsp; name in the output &lt;EM&gt;.csv&lt;/EM&gt; file&amp;nbsp; changed (from &lt;STRONG&gt;oldfieldname&lt;/STRONG&gt; to &lt;STRONG&gt;newfieldname&lt;/STRONG&gt;; in the second case the field name remains unchanged. Why is that? To my eye both code snippets do exactly the same thing.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 15:13:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1260917#M67855</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2023-02-23T15:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMap API : Strange Behavior. Can someone explain?</title>
      <link>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1261552#M67856</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/112163"&gt;@RobertStevens&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;The same happened to me first time I had to use FieldMapping on a script. I don't really know how FielMap object works behind the scenes but it seems that you cannot set &lt;EM&gt;name&lt;/EM&gt; property directly unless you declare a new variable in memory for &lt;EM&gt;outputField&lt;/EM&gt; property.&lt;/P&gt;&lt;P&gt;It's an odd behaviour, but somehow it could be related to the ArcObjectToPythonObject conversion. Digging into FieldMap class, &lt;EM&gt;outputField&lt;/EM&gt; is set with&amp;nbsp;&lt;EM&gt;passthrough_attr&lt;/EM&gt; function defined on _base.py module. And from there it becomes complex enough to lose track of what it is being done.&lt;/P&gt;&lt;P&gt;Hope somebody else could shed some light on this particular behaviour.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 19:01:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1261552#M67856</guid>
      <dc:creator>Kepa</dc:creator>
      <dc:date>2023-02-24T19:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMap API : Strange Behavior. Can someone explain?</title>
      <link>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1261736#M67857</link>
      <description>&lt;P&gt;Hi Kepa&lt;/P&gt;&lt;P&gt;Thanks for your reply. I was wondering whether I could believe my own eyes. The examples in ESRI's documentation use that rather long winded way of creating a fieldmap object. One would think that ESRI might perhaps explain why it is necessary to do it that way. I don;t know why it is with this software that there is always some surprise or undocumeted strangeness lurking around the corner. Like you, I am hoping someone else with more knowledge of ESRI's Python maze can comment.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 02:43:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1261736#M67857</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2023-02-25T02:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMap API : Strange Behavior. Can someone explain?</title>
      <link>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1264291#M67858</link>
      <description>&lt;P&gt;Follow up to original posting: I found this baffling and filed it as a bug. ESRI have confirmed that this behavior of the API is incorrect and&amp;nbsp; new bug has been opened against it. In my bug report I mused that possibly many other APIs might have similar unusual behavior, but that i just speculation on my part. Whatever causes this bug it seems to me inconsistent with Python syntax and semantics. It is almost as thought the equality operator has been redefined as is possible in C++.&lt;/P&gt;&lt;P&gt;ESRI have reproduced this behavior and filed as a bug: &lt;SPAN&gt;BUG-000156266&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 22:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1264291#M67858</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2023-03-07T22:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMap API : Strange Behavior. Can someone explain?</title>
      <link>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1297089#M67859</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;what if you convert fm to string&lt;/P&gt;&lt;P&gt;fm = str(fm). I have noticed that since arcgis pro 3.X i have to add that line&amp;nbsp; (converting your field mapping to string)....&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 13:49:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1297089#M67859</guid>
      <dc:creator>Tomasz_Tarchalski</dc:creator>
      <dc:date>2023-06-08T13:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMap API : Strange Behavior. Can someone explain?</title>
      <link>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1300692#M67995</link>
      <description>&lt;P&gt;Hello Tomaxz&lt;/P&gt;&lt;P&gt;I haven't tried, and will when I have time.&lt;/P&gt;&lt;P&gt;But if you convert to a string how can it have&amp;nbsp; method &lt;STRONG&gt;addInputField &lt;/STRONG&gt;?&lt;BR /&gt;I am confused.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 12:47:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmap-api-strange-behavior-can-someone-explain/m-p/1300692#M67995</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2023-06-19T12:47:06Z</dc:date>
    </item>
  </channel>
</rss>

