[Tutor] why wont this code run?
alan.gauld@bt.com
alan.gauld@bt.com
Mon Jan 27 09:00:03 2003
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C2C604.21DB8A80
Content-Type: text/plain;
charset="iso-8859-1"
What actually happens? Error codes and output are always helpful...
-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
GREENDAY31087@aol.com
Sent: 27 January 2003 01:05
To: tutor@python.org
Subject: [Tutor] why wont this code run?
class Map:
def __init__(self):
self.__grid={} # Don't assume global startroom
def addRoom(self, room, x, y):
if self.__grid.has_key((x,y)):
raise KeyError, "Location occupied"
self.__grid[(x, y)] = room
def getRoom(self, x, y):
return self.__grid[(x, y)]
def getLocation(self, room):
for coord, aRoom in self.__grid.items():
if room == aRoom:
return coord
raise KeyError
class Room:
def __init__(self, map, x=0, y=0):
self.__map = map
map.addRoom(self, x, y)
def dig(direction):
The class TRoom doewsn't align with the class Map.
The dig method is undefined.
There are only 2 class definitions, you never create instances, so its hard
to
know what you think the code will do if it were to "run".
Alan G.
------_=_NextPart_001_01C2C604.21DB8A80
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=674055612-27012003><FONT face=Arial color=#0000ff size=2>What
actually happens? Error codes and output are always
helpful...</FONT></SPAN></DIV>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> tutor-admin@python.org
[mailto:tutor-admin@python.org]<B>On Behalf Of
</B>GREENDAY31087@aol.com<BR><B>Sent:</B> 27 January 2003 01:05<BR><B>To:</B>
tutor@python.org<BR><B>Subject:</B> [Tutor] why wont this code
run?<BR><BR></FONT></DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT face=Arial><FONT size=2>class
Map:<BR> def
__init__(self):<BR>
self.__grid={} # Don't assume global
startroom<BR> def
addRoom(self, room, x,
y):<BR>
if
self.__grid.has_key((x,y)):<BR>
raise KeyError, "Location
occupied"<BR>
self.__grid[(x, y)] = room<BR>
def getRoom(self, x,
y):<BR>
return self.__grid[(x, y)]<BR>
def getLocation(self,
room):<BR>
for coord, aRoom in
self.__grid.items():<BR>
if room ==
aRoom:<BR>
return
coord<BR>
raise KeyError<BR> <BR> class
Room:<BR> def __init__(self,
map, x=0,
y=0):<BR>
self.__map =
map<BR>
map.addRoom(self, x, y)<BR>
def dig(direction):<BR><SPAN class=674055612-27012003><FONT
color=#0000ff> </FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT face=Arial><FONT size=2><SPAN
class=674055612-27012003><FONT color=#0000ff>The class TRoom doewsn't align
with the class Map.</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT face=Arial><FONT size=2><SPAN
class=674055612-27012003><FONT color=#0000ff>The dig method is
undefined.</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT face=Arial><FONT color=#0000ff
size=2><SPAN class=674055612-27012003>There are only 2 class definitions, you
never create instances, so its hard to </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT face=Arial><FONT color=#0000ff
size=2><SPAN class=674055612-27012003>know what you think the code will do if
it were to "run".</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT face=Arial><FONT color=#0000ff
size=2><SPAN class=674055612-27012003></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT face=Arial><FONT color=#0000ff
size=2><SPAN class=674055612-27012003>Alan
G.</SPAN></FONT></FONT></DIV></BLOCKQUOTE></FONT></BODY></HTML>
------_=_NextPart_001_01C2C604.21DB8A80--