472,125 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

problem calling parent's __init__ method

I am trying to call a parent's __init__ method from the child's:

class ArbitraryBlock(InnerBlock):
def __init__(self, codelist, noout=False, **kwargs):
InnerBlock.__init__(self, codelist, noout=noout, **kwargs)
I get this error:

<type 'exceptions.TypeError'>: unbound method __init__() must be
called with InnerBlock instance as first argument (got ArbitraryBlock
instance instead)
I found a thread that talked about the parent and child being
different types, so I tried setting up the parent class 3 different
ways:

class InnerBlock:

class InnerBlock(object):

class InnerBlock(empty_class):

where

class empty_class(object):
def __init__(self,_d={},**kwargs):
kwargs.update(_d)
self.__dict__=kwargs

I still get the same error. Why doesn't this work?

Thanks,

Ryan
Aug 7 '08 #1
1 2422
Ryan Krauss wrote:
I am trying to call a parent's __init__ method from the child's:

class ArbitraryBlock(InnerBlock):
def __init__(self, codelist, noout=False, **kwargs):
InnerBlock.__init__(self, codelist, noout=noout, **kwargs)
I get this error:

<type 'exceptions.TypeError'>: unbound method __init__() must be
called with InnerBlock instance as first argument (got ArbitraryBlock
instance instead)
I found a thread that talked about the parent and child being
different types, so I tried setting up the parent class 3 different
ways:

class InnerBlock:

class InnerBlock(object):

class InnerBlock(empty_class):

where

class empty_class(object):
def __init__(self,_d={},**kwargs):
kwargs.update(_d)
self.__dict__=kwargs

I still get the same error. Why doesn't this work?
For some reason you have two InnerBlock classes in your code. A
demonstration:
>>class A(object):
.... def __init__(self): pass
....
>>class B(A):
.... def __init__(self):
.... A.__init__(self)
....
>>B()
<__main__.B object at 0x2b67aae02c90>
>>class A(object):
.... def __init__(self): pass
....
>>B()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
TypeError: unbound method __init__() must be called with A instance as first
argument (got B instance instead)

Are you perhaps importing your main script into your main script?

Peter
Aug 7 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Gonçalo Rodrigues | last post: by
3 posts views Thread by Christian Dieterich | last post: by
14 posts views Thread by Axel Straschil | last post: by
6 posts views Thread by TPJ | last post: by
reply views Thread by .nu | last post: by
11 posts views Thread by Tool69 | last post: by
4 posts views Thread by amidzic.branko | last post: by
reply views Thread by Jerry Hill | last post: by

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.