Problem with inheritance

12-08-2017 04:54 AM
by Anonymous User
Not applicable

Hi everyone. I'm facing a problem trying to extend the FieldMappings class:

class FeatureFields(FieldMappings😞

def __init__(self, feature😞
super(FieldMappings, self).__init__()

When I try do call the constrcutor:

f = FeatureFields(feature)

The terminal give the following errors:

super(FieldMappings, self).__init__()
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\arcobjects\", line 960, in __init__
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\arcobjects\", line 47, in __init__
for arg in args))
RuntimeError: Object: CreateObject FeatureFields not valid

What I'm doing wrong?

0 Kudos
2 Replies
MVP Legendary Contributor

have you check what is needed as arguments _base and mixins?  can't check those lines

Those line numbers may have changed in 10.5.1 

currently 960 is NetCDFFilePropertiesMixin 

and the _base will fail since the object has to have an arc_object attribute which may mean subclassing isn't permitted or it failed because it wasn't assigned earlier

((arg._arc_object if hasattr(arg, '_arc_object') 

but that could be a line number issue

0 Kudos
by Anonymous User
Not applicable

Yes, in line 960 we have: _BaseArcObject.__init__(self)

Complete code:

class FieldMappingsMixin(object):
   def __init__(self):
      from arcpy.geoprocessing._base import gp_fixargs
   def __iter__(self):
      return iter(self.fieldMappings)

And in, line 47 we have: 

class _BaseArcObject(object):
   _arc_object = None
   def __init__(self, *args, **kwargs):
      """Wrapper for ArcGIS scripting Arc Objects --
      Create a new object instance if no reference is passed in."""
      super(_BaseArcObject, self).__init__()
      self._arc_object = gp._gp.CreateObject(self.__class__.__name__,
         *((arg._arc_object if hasattr(arg, '_arc_object') else arg)
               for arg in args))
      for attr, value in kwargs.iteritems():
         setattr(self._arc_object, attr, value)

0 Kudos