473,385 Members | 1,930 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,385 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 2488
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gonçalo Rodrigues | last post by:
Hi, I have a problem with threads and sockets. I'll try to describe the problem in words with pseudo-code. I've been working on a few classes to make it easier to work with threads. This...
3
by: Christian Dieterich | last post by:
Hi, I need to create many instances of a class D that inherits from a class B. Since the constructor of B is expensive I'd like to execute it only if it's really unavoidable. Below is an example...
14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
0
by: .nu | last post by:
#!/usr/bin/env python # -*- coding: utf-8 -*- # Name: Sleepy Hollow # Author: .nu import wx import os import sys
11
by: Tool69 | last post by:
Hi, I've got a simple but difficult problem : Suppose I've got a Paper class, on wich I can draw i.e a rectangle, a circle or whatever. class Paper(...): def __init__(self, paperx, papery):...
0
by: Soren | last post by:
Hi, I'm trying to create a small GUI program where I can do plots using Matplotlib. I've been trying to borrow code from the examples at the matplotlib website, but I can't get it to work. I...
4
by: amidzic.branko | last post by:
I'm trying to solve a problem using inheritance and polymorphism in python 2.4.2 I think it's easier to explain the problem using simple example: class shortList:
0
by: Jerry Hill | last post by:
On Thu, Aug 7, 2008 at 11:11 AM, Ryan Krauss <ryanlists@gmail.comwrote: This works for me just fine: class InnerBlock(object): def __init__(self, codelist, noout=False, **kwargs):...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.