473,799 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't refer to base class attribute?

I've got a Base class with an attribute "foo" (of type Foo), and a
Derived class (derived from Base). In Derived's constructor, I try to
refer to Base.foo, but python complains:
AttributeError: class Base has no attribute 'foo'

Any ideas? (code below)

=== CODE ===
#!/usr/bin/python

class Foo:
def __init__ (self):
self.x = 3

class Base:
def __init__ (self):
self.foo = Foo()

class Derived(Base):
def __init__(self):
Base.__init__(s elf)
Base.foo.x = 5

Derived()
=== EOF ===

Oct 23 '07 #1
1 3403
On Tue, 23 Oct 2007 18:54:06 +0000, mrstephengross wrote:
I've got a Base class with an attribute "foo" (of type Foo), and a
Derived class (derived from Base). In Derived's constructor, I try to
refer to Base.foo, but python complains:
AttributeError: class Base has no attribute 'foo'
Because the class `Base` doesn't have an attribute `foo`. Just believe
the error message. :-)
Any ideas? (code below)

=== CODE ===
#!/usr/bin/python

class Foo:
def __init__ (self):
self.x = 3

class Base:
def __init__ (self):
self.foo = Foo()

`Base` has no `foo` attribute but *instances* of `Base` have.
class Derived(Base):
def __init__(self):
Base.__init__(s elf)
Base.foo.x = 5
Instances of `Derived` have a `foo` attribute inherited from `Base`. So
the last line should be ``self.foo.x = 5``.

Ciao,
Marc 'BlackJack' Rintsch
Oct 23 '07 #2

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

Similar topics

1
1819
by: 5tein | last post by:
I mean, with XSL functions such as SELECT can I only refer to XML element values or can I somehow also refer to XML attribute values? Is there any way to refer to XML content based on attribute values? Or is it a parsed data only thing? BTW, new to XML; sorry if this is a dumb question. I just haven't seen this explicitly stated anywhere (though by experience it doesn't seem to work).
4
428
by: David | last post by:
I have trying to have a webform inherit controls from another form and can't get it to work Say I have a form that saves the person's demographic info. ****one.aspx**** //I have an object to save the person's name in code behind protected void SavePersonInfo(Person p)
6
4904
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
14
33294
by: Dave Booker | last post by:
It looks like the language is trying to prevent me from doing this sort of thing. Nevertheless, the following compiles, and I'd like to know why it doesn't work the way it should: public class ComponentA { static string s_name = "I am the root class."; public string Name { get {return s_name;} } }
17
15779
by: lm401 | last post by:
I'm trying to work with the following idea: class animal: def __init__(self, weight, colour): self.weight = weight self.colour = colour class bird(animal): def __init__(self, wingspan):
3
4035
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user selects? thanks...
0
2507
by: phobos7 | last post by:
Hi, I'm looking for a way to force a derived class to serialise/serialize as its base class. I was hoping that this was possible by just applying an attribute to the the sub class. public class BaseClass { }
1
1985
by: chris.bahns | last post by:
Hello All, I am fairly new to creating custom attributes, and want to get a better feel for how they should be named. We have a class hierarchy, with a base class called "SequenceCommand". This class has a couple static functions and an embedded class, all of which are referenced in code like "SequenceCommand.Create()" or "SequenceCommand.ArgumentDef". There is also a fairly rich hierarchy of classes under it (maybe 10-15 intermediate...
2
1735
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I defined a WCF callback contract: <ServiceContract()_ Interface IEBAPEvents 'this interface defines the events to be triggered in the clients 'the EBAP pattern defines two events: a progress event and a completion event <OperationContract(IsOneWay:=True)_ Sub OnProgressChanged(ByVal e As FindFilesProgressChangedEventArgs)
0
10260
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.