473,699 Members | 3,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheriting Classes Across Files

In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.

Jul 18 '05 #1
4 1261

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6******** *******@newsrea d2.news.pas.ear thlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.
The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth

Jul 18 '05 #2
I tried that as I understand it. I'm sure I'm making a silly error in all
this. Here is a simple example of what I'm trying:

--- (File super_class.py) ---

class base_class:

def sample():
return "Returned!"

--- (File sub_class.py) ---

import super_class

class derived_class(b ase_class):

def sample2():
return "Returned Twice!"

--- (End) ---

Traceback (most recent call last):
File "/home/tina/python/test/sub_class.py", line 3, in -toplevel-
class derived_class(b ase_class):
NameError: name 'base_class' is not defined
John Roth wrote:

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6******** *******@newsrea d2.news.pas.ear thlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.


The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth


Jul 18 '05 #3

"Tina" <bad_addy@no_do main.com> wrote in message
news:kn******** *******@newsrea d1.news.pas.ear thlink.net...
I tried that as I understand it. I'm sure I'm making a silly error in all
this. Here is a simple example of what I'm trying:

--- (File super_class.py) ---

class base_class:

def sample():
return "Returned!"

--- (File sub_class.py) ---

import super_class

class derived_class(b ase_class):

def sample2():
return "Returned Twice!"

--- (End) ---

Traceback (most recent call last):
File "/home/tina/python/test/sub_class.py", line 3, in -toplevel-
class derived_class(b ase_class):
NameError: name 'base_class' is not defined
That needs to be

class derived_class(s uper_class.base _class):
pass

or else:

import base_class from super_class

HTH

John Roth


John Roth wrote:

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6******** *******@newsrea d2.news.pas.ear thlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.


The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth

Jul 18 '05 #4
Tina:
Instead of "import super_class", I think you need
"from super_class import base_class", or
"from super_class import *", or if you want to use "import super_class",
then define the derived class as
"class derived_class(s uper_class.base _class)"

Mike
Tina wrote:
I tried that as I understand it. I'm sure I'm making a silly error in all
this. Here is a simple example of what I'm trying:

--- (File super_class.py) ---

class base_class:

def sample():
return "Returned!"

--- (File sub_class.py) ---

import super_class

class derived_class(b ase_class):

def sample2():
return "Returned Twice!"

--- (End) ---

Traceback (most recent call last):
File "/home/tina/python/test/sub_class.py", line 3, in -toplevel-
class derived_class(b ase_class):
NameError: name 'base_class' is not defined
John Roth wrote:

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6****** *********@newsr ead2.news.pas.e arthlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.


The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth

Jul 18 '05 #5

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

Similar topics

5
6883
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: // TestA.h --------------------------------------- #include <iostream> enum Aval { FIRST_VALUE,
1
2445
by: john diss | last post by:
hello there everyone.. I have created a class called "ProcessLog" inheriting from XmlDocument and two classes ("UploadedItem", "ProcessError") inheriting from XmlElement. I then have two classes ("UploadedTemplate", "UploadedPresentation") which inherit from "UploadedItem")... so far so good. I have overriden the CreateElement method of "ProccessLog" and it creates the correct elements as expected. The problem is I need to override...
2
2231
by: Peter Bates | last post by:
Hi, I'm just getting used to XSDObjectGen and i have the following question. Can i use a class inherited from a class generated by XSDObjectGen with XmlSerialize? Specifically, I have many xml files arriving from a PC inventory scanner we use. I wish to deserialize them and then process them.
6
6281
by: Russell Mangel | last post by:
Jeffery Richter makes the following statement in two books, the first was written in 2004, the latter in 2002. "You should not define new exception classes derived from ApplicationException; use Exception instead." ..NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library (2004) http://www.aw-bc.com/catalog/academic/product/0,1144,0321154894-DS,00.html Exception Management...
2
9500
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how to do that? Thanks. Tsung-Yu
24
2948
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public vector<Corres>{ public: void addCorres(Corres& c); //it do little more than push_back function. }
7
2498
by: Amu | last post by:
Hi i am stuck up in a part of project where i have to inherit the VC++ template classes into C#.net. Please provide me the solution for this .
5
1552
by: jc | last post by:
RE: Two Classes with the same Data Structure.. saving code? Inheriting a structure? I have two classes. One in Inherits System.Collections.CollectionBase, the other does not, but they both have the identical structure and properties. the only difference between them is there methods and that one is a collection class and the other is not. currently the code starts like this:
4
1696
by: AalaarDB | last post by:
struct base { int x, y, z; base() {x = 0; y = 0; z = 0;}; base(int x1, int y1, int z1) {x = x1; y = y1; z = z1;}; }; struct intermediate1 : public virtual base {}; struct intermediate2 : public virtual base
0
8633
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
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
8947
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,...
1
6552
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
5891
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4392
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
4642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.