[Tutor] Question About Subclasses
Britt Green
britt_green@hotmail.com
Tue, 27 Feb 2001 16:55:12 -0800
Hello,
I'm having some problems getting Python to create a subclass. I have a class
called Items, and then a subclass of that called Containers. Python doesn't
recognize Containers as a valid subclass.
This is what I have in a file called "Classes.py":
class Items:
def __init__(self, name, ip):
self.name = name
self.inPossesion = ip
class Containers(Items):
def __init__(self, name, ip, oc):
Items.__init__(self, name, ip)
self.openClosed = oc
Then within another file called "game.py" I have the following code:
import Classes
cupboard = Containers("cupboard", 0, "closed")
key = Items ("worn key", 0)
When I go to run this code, Python spits this back at me:
>>>
Traceback (innermost last):
File "C:/Program Files/Python20/game.py", line 3, in ?
cupboard = Containers("cupboard", 0, "closed")
NameError: There is no variable named 'Containers'
What am I doing wrong?
Thanks,
Britt
--
It is pitch black. You are likely to be eaten by a grue.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com