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

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 1249

"Tina" <bad_addy@no_domain.com> wrote in message
news:E6***************@newsread2.news.pas.earthlin k.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(base_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(base_class):
NameError: name 'base_class' is not defined
John Roth wrote:

"Tina" <bad_addy@no_domain.com> wrote in message
news:E6***************@newsread2.news.pas.earthlin k.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_domain.com> wrote in message
news:kn***************@newsread1.news.pas.earthlin k.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(base_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(base_class):
NameError: name 'base_class' is not defined
That needs to be

class derived_class(super_class.base_class):
pass

or else:

import base_class from super_class

HTH

John Roth


John Roth wrote:

"Tina" <bad_addy@no_domain.com> wrote in message
news:E6***************@newsread2.news.pas.earthlin k.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(super_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(base_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(base_class):
NameError: name 'base_class' is not defined
John Roth wrote:

"Tina" <bad_addy@no_domain.com> wrote in message
news:E6***************@newsread2.news.pas.earthl ink.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
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: ...
1
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...
2
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...
6
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...
2
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...
24
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...
7
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
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...
4
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 :...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.