[Tutor] Starting classes
Ara Kooser
ghashsnaga at gmail.com
Fri Aug 31 21:06:01 CEST 2007
Hello,
I read Alan Gauld's and How to Think Like a Computer Scientist
section on classes. So I tried to write a simple room class. My goal
is to write a short text adventure using classes. Here is the code:
class Area:
def _init_(self, name, description):
self.name = name
def look(here):
"Look around the place you are in"
print here.description
outside1 = Area("Outside")
outside1.description = "You are standing outside with the town gate to
your back"
self.contents.append("dirt")
look(bedroom)
I get the following error.
Traceback (most recent call last):
File "/Users/ara/Documents/text_advent.py", line 11, in <module>
outside1 = Area("Outside")
TypeError: this constructor takes no arguments
Do the outside1 = Area("Outside) need to be nested in the class or can
they be outside of it?
Thank you.
Ara
--
Quis hic locus, quae regio, quae mundi plaga. Ubi sum. Sub ortu solis
an sub cardine glacialis ursae.
More information about the Tutor
mailing list