473,386 Members | 1,860 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,386 software developers and data experts.

inheritance with new-style classes - help

Okay, I have:
class Base( object ):
def __init__( self ):
self._attrib = "base"
print "Base"
def real( self ):
print "Base.real() is calling base.virtual()"
self.virtual()
def virtual( self ):
print "Base virtual()"
pass

class Mother( Base ):
def __init__( self ):
print "Mother"
super( Mother, self ).__init__()
def virtual( self ):
print self._attrib
print "virtual = Mother"
class Father( Base ):
def __init__( self ):
print "Father"
super( Father, self ).__init__()

def virtual( self ):
print self._attrib
print "virtual = Father"

class Child( Mother, Father ):
def __init( self ):
print "Child"
super( Child, self ).__init__()

self._childAttrib = "child"
def virtual( self ):
print "base attribute = " + self._attrib
print "virtual = Child"
print "childAttrib = " + self._childAttrib

rename = Child

x = rename() Mother
Father
Base x.virtual() base attribute = base
virtual = Child
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/tmp/python-8zAJdg.py", line 51, in virtual
AttributeError: 'Child' object has no attribute '_childAttrib'

Hmmm...interesting....but okay...let's look some more...
x.__dict__

{'_attrib': 'base'}

What??! Where the heck did self._childAttrib go? And why?

Can someone please shine some light here? Please?
Thanks in advance,

Greg

Jul 19 '05 #1
3 1253
BTW, this is on Python 2.3.4.

Jul 19 '05 #2
Doh! Child's __init__ was declared as __init(). Fixing that took care
of it! Sorry for wasting the bandwidth!

Cheers,

Greg

Jul 19 '05 #3

"Greg Copeland" <gt************@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Okay, I have: [snip] self._childAttrib = "child" .... AttributeError: 'Child' object has no attribute '_childAttrib'
x.__dict__

{'_attrib': 'base'}

What??! Where the heck did self._childAttrib go? And why?


I don't immediately see the problem. Failing that, I would rerun with
print 'setting '_childAttrib' # and
print self._childAttrib
bracketing the line where it should be set, and go one from there.

Terry J. Reedy


Jul 19 '05 #4

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

Similar topics

1
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
4
by: Dave Theese | last post by:
Hello all, The example below demonstrates proper conformance to the C++ standard. However, I'm having a hard time getting my brain around which language rules make this proper... The error...
9
by: Code4u | last post by:
My colleagues and I have been discussing techniques for implementing interfaces in C++. We're looking for a mechanism similar to COM's QueryInterface, in which a certain types of objects can be...
11
by: PAul Maskens | last post by:
The form designer adds unnecessary code to the section when using a subclassed control. I've reproduced this in VS.NET 2002 and VS.NET 2003 so it's pretty fundamental. Outline steps: Create a...
1
by: relient | last post by:
Hi, I just started the chapter on "Inheritance" and I'm a bit confused so I have three questions: first, here's the code: using System; using System.Collections.Generic; using System.Text; ...
31
by: John W. Kennedy | last post by:
I quite understand about prototypes and not having classes as such, but I happen to have a problem involving blatant is-a relationships, such that inheritance is the bloody obvious way to go. I can...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
4
by: Joe | last post by:
We are working on a project that requires 3rd parties (ie, consultants) to use our ASP.net webforms in a very reusable manner. The big catch is that we are not allowed to give them source. There...
5
by: Michael Thompson | last post by:
I am new to .Net and OOP techniques; I am not even certain that I using the correct terminology here. I believe that I want to know how to do inheritance. I want to create a custom "string"...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.