Inheriting Classes Across Files
Tina
bad_addy at no_domain.com
Thu Mar 25 18:59:12 EST 2004
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 at no_domain.com> wrote in message
> news:E6K8c.748$Dv2.185 at newsread2.news.pas.earthlink.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
>>
More information about the Python-list
mailing list