Re: Problem with sub-classing
- From: Peter Otten <__peter__@xxxxxx>
- Date: Mon, 17 Jul 2006 20:40:43 +0200
Bernard Lebel wrote:
Hello,"\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\Data\Scripts\bb_pipeline\bb_exportelementgranules.py",
I have this problem when subclassing classes where I get this error:
Traceback (most recent call last):
File "<Script Block >", line 344, in BBExportElementGranules_Execute
from bb_pipeline import bb_exportelementgranules
File
line 101, in ?"\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\Data\Scripts\bb_pipeline\bb_granules\bb_granuleexport\bb_granuleexport_element.py",
oWriter = bbExportGranules()
File
line 73, in __init__\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\plugins\bb_pipeline\bb_pipeline_py.py]
bbExportMeta.__init__( self )
TypeError: unbound method __init__() must be called with bbExportMeta
instance as first argument (got bbExportGranules instance instead)
- [line 343 in
In normal English:
I have class bbExportGranules
bbExportGranules is a sub-class of 6 other classes
In the __init__() of bbExportGranules class, I call the __init__() of
5 of these super-classes.
The init of bbExportGranules:
class bbExportGranules( bbExportMeta, bbExportClusters,
bbExportMaterials, bbExportKinematics, bbExportModels, bbExportMetaToc
):
def __init__( self ):
bbExportMeta.__init__( self )
bbExportClusters.__init__( self )
bbExportMaterials.__init__( self )
bbExportKinematics.__init__( self )
bbExportModels.__init__( self )
And the bbExportMeta class (the error is raised when bbExportGranules
is subclassing that one):
class bbExportMeta:
def __init__( self ):
self.iPreviousAssetVersion = gec.iNOPREVIOUSASSETVERSION
self.iCurrentAssetVersion = gec.iMINCURRENTASSETVERSION
self.sPreviousAssetProject = xsi.getdefaultproject()
Any suggestion? I really, really don't see what I'm doing wrong here,
especially that it actually used to work!
Change bbExportGranules to
class bbExportGranules( bbExportMeta, bbExportClusters,
bbExportMaterials, bbExportKinematics, bbExportModels, bbExportMetaToc
):
def __init__(self, bbExportMeta=bbExportMeta): # the only change
bbExportMeta.__init__( self )
bbExportClusters.__init__( self )
bbExportMaterials.__init__( self )
bbExportKinematics.__init__( self )
bbExportModels.__init__( self )
If it then starts to work again you are probably rebinding bbExportMeta
later in your script, e. g:
.... def method(self): passclass A:
....
.... def method(self):class B(A):
.... A.method(self)
....
.... def method(self): passb = B()
b.method() # no error
class A: # rebinding A
....
Traceback (most recent call last):b.method() # oops
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in method
TypeError: unbound method method() must be called with A instance as first
argument (got B instance instead)
One way to make that happen is to import the same file twice, once as part
of a package and once directly. Solution: never set a path into a
package...
Peter
.
- Follow-Ups:
- Re: Problem with sub-classing
- From: Bernard Lebel
- Re: Problem with sub-classing
- References:
- Problem with sub-classing
- From: Bernard Lebel
- Problem with sub-classing
- Prev by Date: pytables - best practices / mem leaks
- Next by Date: Re: Coding style
- Previous by thread: Problem with sub-classing
- Next by thread: Re: Problem with sub-classing
- Index(es):
Relevant Pages
|