473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with sub-classing

Hello,

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 "\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\D ata\Scripts\bb_pipeline\bb_exportelementgranules.p y",
line 101, in ?
oWriter = bbExportGranules()

File "\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\D ata\Scripts\bb_pipeline\bb_granules\bb_granuleexpo rt\bb_granuleexport_element.py",
line 73, in __init__
bbExportMeta.__init__( self )

TypeError: unbound method __init__() must be called with bbExportMeta
instance as first argument (got bbExportGranules instance instead)
- [line 343 in
\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\pl ugins\bb_pipeline\bb_pipeline_py.py]
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!

Thanks
Bernard
Jul 17 '06 #1
3 1267
Bernard Lebel wrote:
Hello,

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
"\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\D ata\Scripts\bb_pipeline\bb_exportelementgranules.p y",
line 101, in ?
oWriter = bbExportGranules()

File
"\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\D ata\Scripts\bb_pipeline\bb_granules\bb_granuleexpo rt\bb_granuleexport_element.py",
line 73, in __init__
bbExportMeta.__init__( self )

TypeError: unbound method __init__() must be called with bbExportMeta
instance as first argument (got bbExportGranules instance instead)
- [line 343 in
\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\pl ugins\bb_pipeline\bb_pipeline_py.py]
>

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:
>>class A:
.... def method(self): pass
....
>>class B(A):
.... def method(self):
.... A.method(self)
....
>>b = B()
b.method() # no error
class A: # rebinding A
.... def method(self): pass
....
>>b.method() # oops
Traceback (most recent call last):
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

Jul 17 '06 #2
Okay, that make sense.

Now the question is: regarding the re-binding behavior, is this
actually problematic? By that I mean that is it good coding practice
to avoid this issue altogether as much as possible, or is it okay to
live with it if you use the __init__ argument trick you have shown?
Thanks
Bernard

On 7/17/06, Peter Otten <__*******@web.dewrote:
Bernard Lebel wrote:
Hello,

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
"\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\D ata\Scripts\bb_pipeline\bb_exportelementgranules.p y",
line 101, in ?
oWriter = bbExportGranules()

File
"\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\D ata\Scripts\bb_pipeline\bb_granules\bb_granuleexpo rt\bb_granuleexport_element.py",
line 73, in __init__
bbExportMeta.__init__( self )

TypeError: unbound method __init__() must be called with bbExportMeta
instance as first argument (got bbExportGranules instance instead)
- [line 343 in
\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\pl ugins\bb_pipeline\bb_pipeline_py.py]


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:
>class A:
... def method(self): pass
...
>class B(A):
... def method(self):
... A.method(self)
...
>b = B()
b.method() # no error
class A: # rebinding A
... def method(self): pass
...
>b.method() # oops
Traceback (most recent call last):
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

--
http://mail.python.org/mailman/listinfo/python-list
Jul 17 '06 #3
Bernard Lebel wrote:
Okay, that make sense.

Now the question is: regarding the re-binding behavior, is this
actually problematic? By that I mean that is it good coding practice
to avoid this issue altogether as much as possible, or is it okay to
live with it if you use the __init__ argument trick you have shown?
I suggested the "argument trick" for diagnosis only.

One /good/ coding practice is to choose descriptive names for (toplevel)
objects. Another is to avoid

from module import *

style imports which tend to be the most common source of name clashes.
Peter

Jul 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jack | last post by:
How would I add a variable that I will assign to a list of $_POST variables that I extract from a form? My form passes a value for $q. That works fine. What I want to do is run an if/else on it...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
0
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
by: **Developer** | last post by:
I've been asking about a Menu problem I have without results. So here is a test case I've developed that shows the problem. Simply create a soultion with one project containg one form and...
5
by: Dany C. | last post by:
We have install a valid SSL certificate issued to www.mycompany.com on our web server running IIS 6.0 / win2003 SP1. Then we have created a sub domain pointing to the same server for our web...
0
by: anandv81 | last post by:
Hi, I encountered a strange problem while working on an application, the problem goes like this. I am generating a few textboxes at runtime at the server side and added to a placeholder, a...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.