[Tutor] Question About Subclasses
Tue, 27 Feb 2001 20:22:57 -0500
cupboard = Classes.Containers("cupboard", 0, "closed")
it will also work without that change if you subsitute
from Classes import *
but there are a bunch of reasons for *not* doing it this way -- get in the
habit of using the syntax in the first solution
|From: firstname.lastname@example.org [mailto:email@example.com]On Behalf Of
|Sent: Tuesday, February 27, 2001 7:55 PM
|Subject: [Tutor] Question About Subclasses
|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.
|recognize Containers as a valid subclass.
|This is what I have in a file called "Classes.py":
| def __init__(self, name, ip):
| self.name = name
| self.inPossesion = ip
| 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:
|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?
|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
|Tutor maillist - Tutor@python.org